Skip to content

A compiler for the Phosphor programming language

License

Notifications You must be signed in to change notification settings

PhosphorLang/PhosphorCompiler

Repository files navigation

Build Test Coverage

The Phosphor Compiler

A compiler for the Phosphor programming language.

module HelloWorld,

import Standard.Io;

function main ()
{
    Io.writeLine('Hello world!');
}

Table of contents


Usage

External Dependencies

You need the following present on your system:

Compile the compiler

npm install
npm run build

Get the standard library

You will need the standard library for compiling Phosphor code. You can find it here: https://github.com/PhosphorLang/StandardLibrary.
Follow the instructions there to compile the standard library.

Compile your code

Important: Note that the only currently supported platform by now is Linux on x86_64.

For compiling the hello world example, execute the following command:
(You have to replace <path to standard library> with the actual path, possibly ../StandardLibrary/bin if you have cloned the git repository of the standard library next to the repository of the compiler; and <platform> with the target platform, e.g. linuxAmd64.)

node bin/main.js -t <platform> -s <path to standard library> examples/helloWorld.ph helloWorld

Compilation targets

You can compile to any target platform from any supported platform.

Target platforms:

  • Linux on x86_64: linuxAmd64

Supported platforms:

  • Linux on x86_64

Removed target platforms:

  • Linux on x86_64 without LLVM
  • AVR

Description

Components

  1. Lexer (Frontend)
    • Converts a file string into a token list by lexical analysis.
    • Result: Token list
  2. Parser (Frontend)
    • Converts a token list into a syntax tree by syntactical analysis.
    • Result: Syntax tree
  3. Connector (Frontend)
    • Converts a syntax tree into a semantic tree by semantic analysis.
    • Result: Semantic tree
  4. Semantic Lowerer (Middleend)
    • Lowers the complex semantic tree into a simpler set of semantic nodes (i.e. desugaring).
    • Result: Lowered tree
  5. Intermediate Lowerer (Middleend)
    • Further lowers the lowered (semantic) tree into intermediate code which only consists of instructions.
    • Result: Intermediate code
  6. Transpiler (Backend)
    • Transpiles the intermediate code into platform specific Assembly.
    • Result: Assembly code (i.a. via LLVM-IR)
  7. Assembler (Backend)
    • Creates an object file from the Assembly.
    • Result: Object file
  8. Linker (Backend)
    • Links the object files into an executable.
    • Result: Executable file

Examples

You can find a full example of all features here.

More example are in the examples directory;