## Pyjamas Python-to-Javascript Translator

The pyjamas python-to-javascript compiler is actually a language translator. It has two main modes: -O and --strict. The --strict mode aims for full python interoperability, even at the expense of performance, whilst the -O mode is, like gcc's -O option, "optimised" for speed, even at the expense of missing out certain python language features and relying on javascript instead. The Migration Guide best describes the differences.

## Supported syntax

The majority of python 2.5, and parts of python 2.6 syntax are supported, including yield despite only one web browser engine having support for ECMAScript "yield" (which is not used). The yield support is implemented as a state machine, rewriting the code so that it is re-entrant, and can resume on each yield. The features not supported are pretty small and obscure, and include for example, at the time of writing, assignment to variables of list items in for-loop syntax is not (`for [a, b] in enumerate(l)`), whereas assignment to tuples is (`for (a, b) in enumerate(l)`). Overall it is best to read the Migration Guide and go from there.

Multiple inheritance is also supported, as is the creation of metaclasses using three arguments to the builtin "type" function (but a call to "type" with only one argument is not supported, and you should be using isinstance for that, anyway). Object introspection is supported, as are decorators, static methods, exceptions and so on. __new__ however, at the time of writing, is a little iffy. unicode is not supported, as it would be horrendous to implement in javascript, but the long type is supported, emulated correctly as javascript.

One particular feature worth noting: the pyjamas python-to-javascript compiler uses the internal features of python (its compile module) to turn python into an Abstract Syntax Tree. This has - had - the disadvantage that the compiler is - was - tied to one specific version of python (2.5). As of Pyjamas 0.6, it has become possible to use anything from python 2.4 and upwards to compile code with python 2.5 syntax, using the "--internal-ast" option. A port of lib2to3 was used as the basis for an AST which is identical to that created by the c-code in the http://python.org compiler. The plan is to use this at some point to implement "exec" and "eval" builtins, but it has the nice side-effect of allowing people who can only use specific versions of python to reliably compile pyjamas python into javascript.

Overall, the general rule is that whoever wants or needs something, they either work around the limitations of javascript and the pyjs implementation, or they provide a patch to improve the compiler/translator.

## Supported modules

Additionally, the python-to-javascript compiler has available to it some implementations of standard python modules, either in pure python or in hybrid javascript and using web browser built-ins. Here is a list of the current python modules that are partially supported. They have all been contributed by pyjamas developers, and anyone wishing to have particular features that are not yet included should simply write them and submit them as a patch:

        base64.py
        binascii.py
        csv.py
        datetime.py
        math.py
        md5.py
        os.py
        _random.py
        random.py
        re.py
        sets.py
        struct.py
        sys.py
        time.py
        urllib.py

## Supported built-ins

Here, also, is a list of supported built-in functions, classes and types. Again: these have been contributed by various pyjamas developers, and again, if there is a particular function or feature missing, it can be submitted as a patch.

Functions:

        __import__
        abs
        all
        any
        bool
        callable
        chr
        cmp
        delattr
        dir
        divmod
        enumerate
        filter
        float
        getattr
        hasattr
        hash
        hex
        isinstance
        issubclass
        iter
        len
        map
        max
        min
        oct
        open
        ord
        pow
        property
        range
        reduce
        repr
        reversed
        round
        setattr
        sorted
        staticmethod
        str
        sum
        super
        type
        xrange
        zip

Classes:

        ArithmeticError
        AttributeError
        BaseException
        Exception
        GeneratorExit
        ImportError
        IndexError
        KeyError
        LookupError
        NameError
        NotImplemented
        NotImplementedError
        NotImplementedType
        RuntimeError
        StandardError
        StopIteration
        TypeError
        ValueError
        ZeroDivisionError

Types:

        dict
        frozenset
        int
        list
        long
        object
        set
        tuple