> My proposal is then a new language (name still unknown) that will support
> several platform :

Here's a link to a beginning of specification.

Nicolas
Title: 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 if block can be used on the right side of a return, or as function call parameter, or everywhere else an _expression_ can be put.

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 the Dynamic 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. And Color -> 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 Dynamic type if you want to get dynamic behavior). That means that inside a method, we know all the types. You don't have then to declare local variable types since they will get inferred for you by the compiler.

Several common types are already defined in the language. Most of them are abstracts.

  • Dynamic : special type
  • Void : abstract
  • Int : abstract
  • Float : abstract
  • Bool : 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 Arrays by specifying the type parameter. For example Array<Int> is an array of integers and Array<Array<Float>> is a two dimentional array containing floats. You can of course define your own parametrized types. If you want them not to be fully abstract, you can specify some requirements in the type parameter :

    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 Dynamic or have your classes extends Dynamic or set your code into an untyped { } block :

    function iKnowWhatImDoing( o : SomeObject ) : SomethingElse {
        untyped {
            return o.someStrangeMethod();
        }
    }

And now ?

A lot more will come later :)

Author

Nicolas Cannasse

_______________________________________________
osflash mailing list
[email protected]
http://osflash.org/mailman/listinfo/osflash_osflash.org

Reply via email to