> My proposal is then a new language (name still unknown) that will support > several platform :
Here's a link to a beginning of specification. NicolasTitle: Flexible specs
The Flexible language specifications
Introduction
A new language, codename Flexible have just been announced. The goal is to have one single language running on several platforms :
- the Flash platform : compile to SWF and use Flash APIs
- the Brower platform : generate _javascript_ for inclusion in your webpages and use Browser APIs
- the Server platform : compile for NekoVM to power you webpages and use Neko APIs
Different APIs
Before starting with language specification I want to clarify one point. Different platforms means different APIs. There is no MovieClips in Neko and there is no Database access in _javascript_. So we will have one single programming language but each platform will keep its own APIs. Only if you only use the common APIs in one class you'll be able to compile this class for each platform.
My First Class
The syntax is Java/ActionScript/C++ like.
A source code file is composed of a package name followed by several type declarations. In order to enforce the conventions, packages names are composed of several identifiers which are starting with a lowercase letter while type identifiers are always starting with an uppercase letter. The following types are available :
- class
- enumeration
- (... more to come)
Here's one single sample mixing a class and an enumeration :
package my.pack {
enum Color {
red;
green;
blue;
}
class Colors {
static function toInt( c : Color ) : Int {
return if ( c == red ) 0xFF000
else if ( c == green ) 0x00FF00
else 0x0000FF;
}
}
}
We can notice several things here :
- an enumeration define several identifiers which have the enumeration type.
- a class can have methods (static or private/public). All class fields (methods and members) must be typed.
- There is no statement. For exemple
block can be used on the right side of a return, or as function call parameter, or everywhere else an _expression_ can be put.if
The Type System
The Type System is more rich that usual OO languages. There is several kind of types available :
- Objects : objects are declared using classes. Each class can extend a single class (using inheritance) and can implements several classes (this is prototyping).
- Anonymous Objects : it's possible to define anonymous objects such as
{ x : Int; y : Int } . - Dynamic Objects : the
Dynamic class have an infinite number of fields and methods, each having theDynamic type. Classes can extends Dynamic in order to get dynamic behavior. - Abstract Types : enumeration are abstract types. They define a finite number of instance of this type. The empty enumeration for exemple, although it has a name, can't be constructed.
- Function Types : when you want to define function types, you can define them by listing the arguments followed by the return type and separated with arrows. For exemple
Int -> Void is the type of a function taking an Int as argument and returning Void. AndColor -> Color -> Int takes two Color arguments and returns an Int.
As we said before, all objects fields (members and methods) must be fully typed (although you can use the
Several common types are already defined in the language. Most of them are abstracts.
Dynamic : special typeVoid : abstractInt : abstractFloat : abstractBool : enum { true; false; }
Class Parameters
You can define class parameters in order to have one single class implementing different behavior. This is a way to get polymorphism :
native class Array<T> {
function new () : Void;
function get( pos : Int ) : T;
function set( pos : Int, elt : T ) : Void;
...
}
Then you can use different kind of
class MyClass<T extends MyObject> {
var o : T;
function foo() : Void {
o.myMethod();
}
...
}
Going Dynamic
When you want to have dynamic behavior, you can either type some variables as
function iKnowWhatImDoing( o : SomeObject ) : SomethingElse {
untyped {
return o.someStrangeMethod();
}
}
And now ?
A lot more will come later :)
Author
_______________________________________________ osflash mailing list [email protected] http://osflash.org/mailman/listinfo/osflash_osflash.org
