D2 (d2lang) is a strongly-typed, statically-typed, (mostly) type-inferred 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
Contributing
See the contributor's guide.
Installing
The first 4 are required:
Running Tests
Run bazel test ... from the root directory.
Running the compiler
See docs/running.md.
Caveats
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.
Language sample
Canonical 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
Why did I build D2?
See docs/history