Git Product home page Git Product logo

phosphorcompiler's Introduction

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;

phosphorcompiler's People

Contributors

benediktmagnus avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

langbot-mirrors

phosphorcompiler's Issues

External function declarations

Allow to declare function declarations without an implementation. This would make header files for libraries (most importantly: the standard library) possible.

Proposed syntax (file scope):

external function functionName ();

Import functionality

It should be possible to import file from the file system or the standard library modules. For now, it could be enough to include them as they were part of the file with the import statement.
No file should be included twice.

Relative imports:

import './fileFromSameFolder.ph';
import '../fileFromParentFolder.ph';

Import from root folder (where the main file is):

import '/fileFromRootFolder.ph';

Import from the standard library:

import 'standardLibraryModule';

The parser should check every token for validity.

At the moment, the parse consumes tokens via consumeNextToken() without checking them at all. It should be verified that these tokens are actually the tokens that the parser expect.
consumeNextToken() could, for example, expect a token kind or a list of token kinds that are valid and throw if the found token is not one of them.

Support for array literals

There should be support for array literals as a starting point into arrays in general as it is the easiest to have: Simple structure, static and without any defaults needed.

Syntax:

// One-dimensional integer array literal:
var array := [0, 2, 4];

Definition and documentation of the intermediate representation

The upcoming intermediate representation must be defined the same way the syntax and semantic trees have been defined.
Furthermore, a proper documentation is especially desirable as the intermediate code will be more general and less self-explanatory than the internal trees. Besides that, it must be human readable (and understandable), which is much easier with a proper documentation.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.