D2 (d2lang) is a strongly-typed, statically-typed, inferred-type compiled language. Its syntax draws from C, Java and Python.
The D2 compiler currently compiles to X64 assembly language only. It uses
nasm
and gcc
to assemble and link, respectively, to Windows executables.
There are hooks to support other architectures; the intermediate language is (mostly) target-agnostic and a 8085 backend is partially implemented.
See the overview for a more comprehensive description of the types, control structures, operators and statements in D2.
NOTE: D2 is not related in ANY way to "The D Programming Language" except by coincidence of name.
A PLASS Program
See the contributor's guide.
The following 4 are required:
Run bazel test ...
from the root directory.
See docs/running.md.
Only compiles to Intel x64. Only links against the Windows version of the gcc
C Runtime Library. Can only use nasm
and gcc
.
There are various bugs.
Canonical hello world:
println "Hello world"
// Ported from toy (http://www.graysage.com/cg/Compilers/Toy/hanoi.toy)
PEGS = ["", "left", "center", "right"]
printPeg: proc(peg: int) {
print PEGS[peg]
}
hanoi: proc(n: int, fromPeg: int, usingPeg: int, toPeg: int) {
if n != 0 {
hanoi(n - 1, fromPeg, toPeg, usingPeg)
print "Move disk from "
printPeg(fromPeg)
print " peg to "
printPeg(toPeg)
println " peg"
hanoi(n - 1, usingPeg, fromPeg, toPeg)
}
}
n = 5 // defines global
hanoi(n, 1, 2, 3)
See more samples
See docs/history