/SDC

The Stupid D Compiler

Primary LanguageDGNU General Public License v3.0GPL-3.0

SDC - The Stupid D Compiler

This is the home of a D compiler. SDC is at the moment, particularly stupid; it is a work in progress. Feel free to poke around, but don't expect it to compile your code. I don't know what I'm doing in terms of compiler writing. If you find some horrible design decision, that's most likely why.

The code is released under the GPL (see the LICENCE file for more details). Contact me at b.helyer@gmail.com

Last tested with: DMD releases 2.057 and 2.058 on the 6th of March.

Features

What follows is a very high level overview of what's done, and what's still to do. This list is incomplete. SDC is in a state of flux, and this is likely to be out of date.

Lexer

  • Scan and handle multiple encoding formats. [yes.] -- in so far all code is treated as UTF-8 and its BOM is eaten; other BOMs are rejected.
  • Handle leading script lines. [yes.]
  • Split source into tokens. [yes.]
  • Replace special tokens. [yes.]
  • Process special token sequences. [yes.]

Parser

  • Parse module declarations. [yes.]
  • Parse attribute declarations. [yes.]
  • Parse import declarations. [yes.]
  • Parse enum declarations. [yes.]
  • Parse class declarations. [partially.]
  • Parse interface declarations. [no.]
  • Parse aggregate declarations. [partially.]
  • Parse declarations. [partially.]
  • Parse constructors. [yes.]
  • Parse destructors. [yes.]
  • Parse invariants. [no.]
  • Parse unittests. [yes.]
  • Parse static constructors. [yes.]
  • Parse static destructors. [yes.]
  • Parse shared static constructors. [yes.]
  • Parse shared static destructors. [yes.]
  • Parse conditional declarations. [yes.]
  • Parse static asserts. [yes.]
  • Parse template declarations. [partially.]
  • Parse template mixins. [no.]
  • Parse mixin declarations. [partially.]
  • Parse statements. [partially.]

Codegen

  • Import symbols from other modules. [yes.]
  • Apply attributes. [partially.]
  • Enums. [yes.]
  • Structs. [partially.]
  • Classes. [partially.]
  • Functions. [partially.]
  • Overloaded functions. [yes.]
  • Function pointers. [yes.]
  • Local variables. [yes.]
  • Global variables. [yes.]
  • Alias declarations. [partially.]
  • Expressions. [partially.]
  • Label statement. [yes.]
  • If statement. [yes.]
  • While statement. [yes.]
  • Do statement. [yes.]
  • For statement. [yes.]
  • Switch statement. [no.]
  • Final switch statement. [no.]
  • Case statement. [no.]
  • Case range statement. [no.]
  • Default statement. [no.]
  • Continue statement. [no.]
  • Break statement. [no.]
  • Return statement. [yes.]
  • Goto statement. [partially.]
  • With statement. [no.]
  • Synchronized statement. [no.]
  • Try statement. [no.]
  • Scope guard statement. [no.]
  • Throw statement. [no.]
  • Asm statement. [no.]
  • Pragma statement. [no.]
  • Mixin statement. [yes.]
  • Foreach range statement. [yes.]
  • Conditional statement. [yes.]
  • Static assert. [yes.]
  • Template mixin. [no.]
  • Templated scope. [partially.]

What Can It Compile?

See the tests directory for a sample of what is/should-be working. libs/object.d contains the current (temporary) object.d file for SDC.

Roadmap

This just me thinking outloud about what features I want, when.

0.1

  • druntime compiles

0.2

  • phobos compiles

0.3

  • inline assembler

1.0

  • dmd calling convention compatibility
  • self hosting

2.0

  • extern (C++)

Compiling SDC on Linux

You'll need make and the latest DMD installed. Install LLVM 3.0. Run make. Copy bin/sdc into your $PATH somewhere. You'll need to create a file, either /etc/sdc.conf or ~/.sdc.conf (the latter may change to ~/.local/share/sdc/sdc.conf at some point, so be warned) with contents like so:

{
    "defaultImportPaths":["~/path/to/SDC/libs"],
    "defaultFlags":["-m64", "--debug"]
}

The last bit is optional, but SDC needs to know where to find object.d is the point. Then you can compile runner.d with dmd and run it to run the test suites. There will be a handful of failures, but the majority (> 95%) should pass.

SDC with DMD/Windows

(These instructions are from Jakob, so please don't contact me regarding them.)

The following are required for LLVM to function on Windows:

  • LLVM >= 3.0
    • SDC requires the core libraries as a DLL, and the llc and opt tools
  • MinGW
    • SDC requires gcc, as well as GNU make for the makefile
The above have not been updated for LLVM 3.0, unfortunately. Until then, you'll have to convert it with `implib` or so. Good luck! -B.

For the LLVM tools, grab "LLVM Binaries for Mingw32/x86" on the [LLVM download page](http://llvm.org/releases/download.html).
### Setup
Extract the LLVM DLL binary archive to the SDC repository, then build with `make -f Makefile.windows`.
When running SDC, make sure `gcc`, `llc` and `opt` are available in your PATH.

To run the tests, execute `dmd runner.d` to build the test-runner application found in `tests/`, then run it with `runner`.