A compiler for the Phosphor programming language.
module HelloWorld,
import Standard.Io;
function main ()
{
Io.writeLine('Hello world!');
}
You need the following present on your system:
- For all target platforms:
- Node.js >= 18.12.1
- Linux Amd64:
- LLVM = 14.0.0
- GNU x86_64-linux-gnu-as >= 2.38
- GNU ld >= 2.38
npm install
npm run build
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.
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
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
- Lexer (Frontend)
- Converts a file string into a token list by lexical analysis.
- Result: Token list
- Parser (Frontend)
- Converts a token list into a syntax tree by syntactical analysis.
- Result: Syntax tree
- Connector (Frontend)
- Converts a syntax tree into a semantic tree by semantic analysis.
- Result: Semantic tree
- Semantic Lowerer (Middleend)
- Lowers the complex semantic tree into a simpler set of semantic nodes (i.e. desugaring).
- Result: Lowered tree
- Intermediate Lowerer (Middleend)
- Further lowers the lowered (semantic) tree into intermediate code which only consists of instructions.
- Result: Intermediate code
- Transpiler (Backend)
- Transpiles the intermediate code into platform specific Assembly.
- Result: Assembly code (i.a. via LLVM-IR)
- Assembler (Backend)
- Creates an object file from the Assembly.
- Result: Object file
- Linker (Backend)
- Links the object files into an executable.
- Result: Executable file
You can find a full example of all features here.
More example are in the examples directory;