Skip to content

D2 is a strongly-typed, statically-typed, (mostly) inferred-type compiled language.

License

Notifications You must be signed in to change notification settings

dplassgit/d2lang

Repository files navigation

d2lang

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

Contributing

See the contributor's guide.

Installing

The following 4 are required:

  1. bazel

  2. nasm

  3. gcc

  4. Java 11 or higher

  5. Optional: Eclipse and git bash shell (mingw64)

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:

println "Hello world"

Tower of Hanoi

// 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