xp-lang/compiler

This package is abandoned and no longer maintained. No replacement package was suggested.

XP Compiler

v7.1.1 2016-10-03 10:18 UTC

README

Build Status XP Framework Module BSD Licence Required PHP 5.5+ Supports PHP 7.0+ Supports HHVM 3.5+ Latest Stable Version

XP language is a feature-rich, typed and compiled programming language, based on the popular PHP language and designed to syntactically support features of the XP Framework. The source you write and compile with it can make use of the XP Framework's foundation classes. As the language itself is written in the XP Framework, no binary or proprietary extensions are needed!

Getting started

Like in the XP framework, the entry point is always a class. In their most simple form, these classes have a static main() method. To try it out, create a file called HelloWorld.xp with the following contents:

public class HelloWorld {
  public static void main(string[] $args) {
    util.cmd.Console::writeLine('Hello World!');
  }
}

Then compile and run it!

$ xp HelloWorld
Hello World!

Differences

The things you will have noticed are:

  • Classes may also have modifiers.
  • The extends Object is optional and added by the compiler if omitted.
  • The keyword function is gone and replaced by the return type. Because the main() method does not return anything, we use void.
  • An array type is written as component[]
  • Variables still have dollar signs. This makes it easy to spot them, that's why we've decided to keep this!
  • Fully qualified classnames are written with dots.
  • The object operator is also a dot (at the same time, the string concatenation operator is now the tilde, ~).

Features

The XP Language features - among others - support for the following:

  • Namespaces (which are called packages)
  • Imports, static imports and "on-demand" imports (import util.*;)
  • Varargs syntax
  • Distinguishable types for arrays and maps
  • Class literal ::class, and finally - also for PHP < 5.5!
  • Properties with get and set, and Indexers
  • Syntactic support for the following XP Framework features: Typesafe enumerations, Annotations, Generics, the with statement and a throws clause

Further reading

To get an overview of XP Language's features, these are good reads:

Developing

In order to change XP Language and/or the Compiler itself, you need to clone this repository, e.g. using Git Read-Only:

$ cd [path]
$ git clone git://github.com/xp-lang/compiler.git

Directory structure

[path]/compiler
 |- ChangeLog.md      # Version log
 |- README.md         # This file
 |- module.pth        # Module classpath
 `- src               # Sourcecode, by Maven conventions
    |- main
    |  `- php
    `- test
       |- php
       `- config      # Unittest configuration

Using it

Add that path to your use setting before the global module path inside your xp.ini, e.g.:

use=~/devel/xp-framework/core:~/devel/xp-lang/compiler
                              ^^^^^^^^^^^^^^^^^^^^^^^^

On Windows systems, use ; as separator

Enjoy!

Contributing

To contribute, use the GitHub way - fork, hack, and submit a pull request!