[ANN] pyjamas pyv8run converts python to javascript, executes undercommand-line

L

lkcl

just for fits and giggles and also because i'm getting fed up of using
web browsers as part of the pyjs development cycle instead of the
command-line, the pyjamas pyv8run.py has been brought back up-to-
scratch, and can now execute the pyjamas LibTest regression tests with
a 99.95% pass rate.

pyv8run is a back-to-back combination of google's v8 engine + a
library by flier liu which makes extensive use of python-boost (http://
code.google.com/p/pyv8) + the pyjamas python-to-javascript compiler.
the initial experiment some months ago, with pyjamas 0.5, produced a
python ACcellerator with a 10x performance increase; the latest
0.6~svn pyjamas compiler results in a python DEcellerator with a
[finger-in-the-air] 10x performance DEcrease, thanks to the addition
of several python strictness features. hurrah! :)

perhaps it is the fact that the 0.5 test used google's stable x86
libv8, and the 0.6~svn test used google's alpha-release of amd64 libv8
- who knows, who cares, it's just hilarious to convert arbitrary
python code into javascript and have it do 99.95% the same job.

on the roadmap of this sub-sub-project of pyjamas is:

* to throw pyv8run at the standard http://python.org regression tests
and see what sticks

* to improve the pyjamas compiler and/or alter the adapted lib2to3
parser/AST library in order to create a stand-alone, self-bootstrapped
_javascript_ version of the pyjamas python-to-javascript compiler.
this is _mandatory_ in order to support "eval" and "exec" - execution
of python _source_ code - inside web browsers (and under a js> prompt
such as spidermonkey or d8)

this latter goal has already been hilariously achieved by the
(completely independent) skulpt project: http://skulpt.org/ whose
parser/AST code the pyjamas project has borrowed - and back-ported
from javascript to python. you can see their demo python prompt on
the main page, and use it to mash your own web browser of choice into
submission.

the pyjamas project is taking a slightly different approach to achieve
this same goal: beat the stuffing out of the pyjamas compiler, rather
than hand-write such large sections of code in pure javascript, and
double-run regression tests (once as python, second time converted to
javascript under pyv8run, d8 or spidermonkey).

anyway, just thought there might be people who would be intrigued (or
horrified enough to care what's being done in the name of computer
science) by either of these projects.

l.
 
P

Paul Boddie

the pyjamas project is taking a slightly different approach to achieve
this same goal: beat the stuffing out of the pyjamas compiler, rather
than hand-write such large sections of code in pure javascript, and
double-run regression tests (once as python, second time converted to
javascript under pyv8run, d8 or spidermonkey).

anyway, just thought there might be people who would be intrigued (or
horrified enough to care what's being done in the name of computer
science) by either of these projects.

I've added pyjamas to the implementations page on the Python Wiki in
the compilers section:

http://wiki.python.org/moin/implementation

The Skulpt implementation, already listed by Cameron Laird on his page
of Python implementations, is now also present, although using it is a
bit like using various 8-bit microcomputer emulators which assume a UK
keyboard and ignore the "replacement" keys on my own non-UK keyboard.

Paul
 
D

Daniel Fetchinson

the pyjamas project is taking a slightly different approach to achieve
I've added pyjamas to the implementations page on the Python Wiki in
the compilers section:

http://wiki.python.org/moin/implementation

In what way is pyjamas a python implementation? As far as I know
pyjamas is an application written in python that is capable of
generating javascript code. Does this make it a 'python
implementation'? That would be news to me but I've been wrong many
times before.

Cheers,
Daniel
 
R

Robert Kern

Daniel said:
In what way is pyjamas a python implementation? As far as I know
pyjamas is an application written in python that is capable of
generating javascript code. Does this make it a 'python
implementation'? That would be news to me but I've been wrong many
times before.

It converts Python code to Javascript.

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
 
D

Diez B. Roggisch

Daniel said:
In what way is pyjamas a python implementation? As far as I know
pyjamas is an application written in python that is capable of
generating javascript code. Does this make it a 'python
implementation'? That would be news to me but I've been wrong many
times before.

It is an implementation. It takes python-code, and translates that to JS
- so you code in Python, but the code is executed inside a JS-"VM".

Diez
 
E

exarkun

It converts Python code to Javascript.

The question is whether it converts Python code to JavaScript code with
the same behavior. I think you're implying that it does, but you left
it implicit, and I think the point is central to deciding if pyjamas is
a Python implementation or not, so I thought I'd try to make it
explicit.

Does pyjamas convert any Python program into a JavaScript program with
the same behavior? I don't intend to imply that it doesn't - I haven't
been keeping up with pyjamas development, so I have no idea idea. I
think that the case *used* to be (perhaps a year or more ago) that
pyjamas only operated on a fairly limited subset of Python. If this was
the case but has since changed, it might explain why some people are
confused to hear pyjamas called a Python implementation now.

Jean-Paul
 
R

Robert Kern

The question is whether it converts Python code to JavaScript code with
the same behavior. I think you're implying that it does, but you left
it implicit, and I think the point is central to deciding if pyjamas is
a Python implementation or not, so I thought I'd try to make it explicit.

Does pyjamas convert any Python program into a JavaScript program with
the same behavior?

Barring the unimplemented libraries and bugs, yes. If you read the original post
in this thread, you will see that on the roadmap is running the entire Python
regression suite.

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
 
D

Daniel Fetchinson

the pyjamas project is taking a slightly different approach to achieve
Barring the unimplemented libraries and bugs, yes. If you read the original
post in this thread, you will see that on the roadmap is running the entire
Python regression suite.

Okay, this is true, something I missed.

Cheers,
Daniel
 
R

Robert Kern

John said:
No, it's getting close to running the entire Pyjamas regression suite,
which is something else.

I was referring to this statement:

"""
on the roadmap of this sub-sub-project of pyjamas is:

* to throw pyv8run at the standard http://python.org regression tests
and see what sticks
"""

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
 
L

lkcl

In what way is pyjamas a python implementation? As far as I know
pyjamas is an application written in python that is capable of
generating javascript code.

it's strictly speaking, according to wikipedia, a "language
translator". i'm just in the process of adding an AST parser (based
on lib2to3, from sgraham's work in skulpt) which will become the basis
of an "exec" function, just like in the skulpt demo.

also to answer your question: pyjamas has [roughly] two modes: -O and
--strict. "-O" is the one where you have to write in a subset of
python, and you can (unfortunately) do things like 5 + "px" (which
doesn't throw an exception). this saves _vast_ amounts of CPU
cycles.

"--strict" as you would expect is the python-strict converter, where
we're beginning to add implementations of __add__ etc. etc. and
generally cope with the nasty grungy bits of javascript that would
otherwise make arbitrary python applications keel over.

l.
 
L

lkcl

Does pyjamas convert any Python program into a JavaScript program with
the same behavior?

that's one of the sub-goals of the pyjamas project, yes.
I don't intend to imply that it doesn't - I haven't
been keeping up with pyjamas development, so I have no idea idea. I
think that the case *used* to be (perhaps a year or more ago) that
pyjamas only operated on a fairly limited subset of Python. If this was
the case but has since changed, it might explain why some people are
confused to hear pyjamas called a Python implementation now.

yup. "-O" now equals [roughly] pyjamas 0.3 to 0.5p1 behaviour, aka
"pythonscript" - a mishmash of python grammar/syntax with javascriptic
execution.

since kees joined, he's been steaming ahead with python
interoperability (--strict option). he first started out by improving
the pyjamas compiler and support libraries to the point where the
python version of http://puremvc.org could be compiled to javascript
as-is, and it's gone from there, really.

on the roadmap is to take a look at what the unladen/swallow team
have done, when they get to their stage 2 "unboxing", and see if
calling out to PyV8 or Python-SpiderMonkey objects can be done from
intobject.c, longobject.c etc.

if the early experiments are anything to go by, python will then have
_yet another_ python accelerator.

but, really, for that to properly happen, python has _got_ to get
some type-checking decorators on functions:

@paramtypecheck(foo=int, bar=[int, str])
@paramtypecheck(int, [int, str]) # or this
@returntypecheck(int)
def randomfunction(foo, bar):
if isinstance(bar, str):
bar = int(bar)
return foo + bar


this kind of type-checking guidance would _drastically_ help out all
of the compilers (such as that python-to-c++ one), and could probably
also be utilised by http://python.org itself, ultimately, to speed up
function execution.

it's also just good software engineering practice to check parameters
and return results.

l.
 
D

Daniel Fetchinson

the pyjamas project is taking a slightly different approach to achieve
it's strictly speaking, according to wikipedia, a "language
translator".

Yep, this sounds more like what I originally had in mind.
But if people insist on calling it a python implementation, it's fine by me :)

Cheers,
Daniel

i'm just in the process of adding an AST parser (based
on lib2to3, from sgraham's work in skulpt) which will become the basis
of an "exec" function, just like in the skulpt demo.

also to answer your question: pyjamas has [roughly] two modes: -O and
--strict. "-O" is the one where you have to write in a subset of
python, and you can (unfortunately) do things like 5 + "px" (which
doesn't throw an exception). this saves _vast_ amounts of CPU
cycles.

"--strict" as you would expect is the python-strict converter, where
we're beginning to add implementations of __add__ etc. etc. and
generally cope with the nasty grungy bits of javascript that would
otherwise make arbitrary python applications keel over.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top