Language

Closures and "this"

at 2012-04-08 in PHP5Language by friebe

What does the following (plain PHP) do?

  class Lambda {
protected
$greeting= 'Hello';

protected
function greeter() {
return
function($who) { return $this->greeting.' '.$who; };
}

public
static function main($args) {
$l= new self();
$greeter= $l->greeter();
echo
$greeter($args[0] ?: 'World'), PHP_EOL;
}
}

Lambda::main
(array_slice($argv, 1));

Well, we'd say it should print Hello World. And that, indeed, is what it does when invoked with PHP 5.4.

Unfortunately, with PHP 5.3, this does not work (support for $this was first removed and then re-added again after a lengthy discussion on the php-internals mailing list). To make things , in other languages and platforms, things work even more differently. This is why we've started an RFC on this topic. Its goal is to define consistent behaviour over all platforms XP language runs on. For details, see here.



XP on NodeJS: Class constants, annotations, stacktraces

at 2012-03-21 in LanguageExperiments by friebe

More work has been put into the XP on NodeJS experiment: The compiler now knows how to correctly emit class constants and annotations, and a couple of minor bugs have been fixed. The bigger efforts have gone into stabilizing the XP "Microkernel" (which is what I've decied to call the miniature XP Framework implementation written in JavaScript and adopted to NodeJS as well as Windows Scripting Host):

  • We're finally getting inheritance right (or are we ? - :-))?
  • Class path is now assembled via class.pth files
  • Classes can reside freely inside any of the class path elements
  • Stack traces are now shown, including method names and arguments
  • Parent class reflection now works
  • The entry point scripts (tools/node.js and tools/cscript.js) are now generated from a common base
  • When these are invoked without arguments, they show version and classpath info
Here's something for you visually oriented people:

Screenshot

Finally, now, also the emitter dictates the file extension instead of it being hardcoded, so compiling is now completely hassle-free, no more moving the generated .class.php files around.

To get started, visit https://github.com/thekid/xp-js !



XP on NodeJS: Flow control, exceptions, loops

at 2012-03-11 in ExperimentsLanguage by friebe

The XP on NodeJS experiment continues to grow, with the following now implemented:

  • Flow control, via if / else
  • Exceptions, try, catch, throw and finally
  • Loops - foreach, for, do and while
  • ARM blocks

A full list of changes can be seen in the compare view.



XP on NodeJS

at 2012-02-26 in LanguageExperiments by friebe

Following discussions with Claus and Alex, with the XP compiler's long-thought-about strategy of enabling us to decouple the framework and the platform in mind, and based on the "JSXP" experiment I had started about a year ago, I created a first draft of a write-once, compile, run-multiple approach.

This is the starting point, the XP language in a file called Greet.xp.

public class Greet {
protected string
$greeting = 'Hello';

public void printGreeting
(string? $name) {
util.cmd.Console::writeLine
($this.greeting, ' ', $name);
}

public
static void main(string[] $args) {
new self().printGreeting($args[0]);
}
}


(more)

The new lang.Closeable interface and ARM blocks

at 2010-12-31 in LanguageExamples5.8-SERIES by friebe

The new lang.Closeable interface and the io.streams classes being retrofitted to implement it may not seem very useful on the first glance, although they serve the purpose of supporting the so-called ARM blocks. These are a feature supported by XP Language and reuse the try keyword:

  try ($expression[, $expression[, ...]]) {
// Statements
}

Any of the expressions are expected to be instanceof lang.Closeable and their close() methods are guaranteed to be called in the declaration order regardless of whether the block raises an exception or not.


(more)

XP language cheat sheet: Differences from PHP

at 2010-10-10 in Language by friebe

Now that we know the basics about the XP language - how to write a "hello world" application, how to compile and run it, and after looking at the underlying type system, and have seen both is quite similar to PHP - let's explore the differences, the object and concatenation operators, changed foreach, array and map syntaxes, the removed function keyword, as well as the now syntactically supported annotations, chaining, enumerations, varargs, and finally, the finally block.


(more)

The XP language's type system

at 2010-10-10 in Language by friebe

As promised in the first article of our XP language series, we will have a look at the type system. The XP language knows about the following types:

  • Primitives - The following primitives exist: int, float, string and bool
  • Reference types - Classes, interfaces and enums, e.g. lang.Object, util.log.Traceable and util.DateInterval
  • Arrays - An array is a zero-based and continuously numbered list of any type, e.g. string[] or util.Date[].
  • Maps - A map is a hashtable mapping string keys to any type, e.g. [:string] or [:lang.XPClass]
  • The variable type - Marks a type that may either be a primitive or any reference type, declared with the keyword "var". The compiler will not be able to verify type correctness in this case and will warn about this - checks will be deferred until runtime.
Member variables, method parameters and return types need to be typed, while local variables don't - their type will be inferred on initialization.


(more)

First steps with the XP Language

at 2010-09-24 in LanguageExamples by friebe

The XP language is not completely different from the way PHP works, it keeps the flexibility and the general "look and feel" while adding syntactical support for features PHP doesn't support or doesn't support in all versions the XP Framework runs on.

Like in the XP framework, the entry point is always a class. In their most simple form, these classes have a static main() method. An example:

  public class HelloWorld {
public
static void main(string[] $args) {
util.cmd.Console::writeLine
('Hello World from ', self::class.getName(), '!');
}
}
OK, this doesn't look too unfamiliar, does it?


(more)

Introducing: The next big thing

at 2010-09-24 in RFCsLanguage5.8-SERIES by friebe

If you have recently updated your SVN checkout, you may have seen a line like the following flying by:

U    devel/xp/trunk/rfc/0052.rfc.txt
RFC #0052? Wait? Wasn't that this really old idea about something with compilation and total world domination? Right - scroll up a couple of lines in that svn update output and find well-sounding names ranging from DeadCodeElimination, Operator and TypeInstance to DefaultDiagnosticListener.

Yes, we now have a compiler!

It's optional, yes, and it doesn't require any special PHP setup, .dll, .so, .bundle, configuration, or anything else to work. Just XP.

So, over the next time, we will provide a series of blog entries introducing the language, the compiler, optimizations, checks, the API. Stay tuned:-)



Subscribe

You can subscribe to the XP framework's news by using RSS syndication.


Categories

News
General
PHP5
Announcements
RFCs
Further reading
Examples
Editorial
EASC
Experiments
Unittests
Databases
5.8-SERIES
Unicode
Language
5.9-SERIES