I would like to enter Summer of Pypy with my proposal to make a javascript interpreter. I had a chat with some nice people in #pypy and they thought it was a good idea. So I checked the code and started looking at what should/can do on 2 months of work ( I don't know if there is this limitation on time). I am a litle lost with all the code from pypy and the idea of making another interpreter so I am posting here my ideas and I am specting your feedback. What do you think I need to do? define a javascript virtual machine or do simple direct interpretation of the source? Should I use the parser defined on pyparsing (this one seems really nice) or write one manually? What I am certain is that it need to have an Interpreter so people can play with it. I should probably write more, but I want to know what you all think about this proposal. ps: I had another idea of translating readline to ctype and make it work on windows also like the one in ipython and also translating sqlite so people can try to run their webframeworks on pypy, but the js interpreter seems more important. -- Leonardo Santagada (http://www.lomohomes.com/retype) Não se preocupe com o que os outros vão fazer. O melhor jeito de prever o futuro é inventa-lo. - Alan Kay
On 11 Aug 2006 at 18:59, Leonardo Santagada wrote:
I would like to enter Summer of Pypy with my proposal to make a javascript interpreter. I had a chat with some nice people in #pypy and they thought it was a good idea. So I checked the code and started looking at what should/can do on 2 months of work ( I don't know if there is this limitation on time). I am a litle lost with all the code from pypy and the idea of making another interpreter so I am posting here my ideas and I am specting your feedback.
What do you think I need to do? define a javascript virtual machine or do simple direct interpretation of the source?
Maybe javascript can compile to Python byte code. Lenard Lindstrom <len-l@telus.net>
Hi Lenard, On Fri, Aug 11, 2006 at 06:50:31PM -0700, Lenard Lindstrom wrote:
Maybe javascript can compile to Python byte code.
No, that wouldn't work. The two language's object models are different, as is always the case between dynamic languages, so you cannot just map the syntax of one to the bytecode of the other. Armin
Hi Armin, I must be missing something here. Isn't Python's object model defined by the type objects themselves? So implement a javascript prototype type. Create the necessary javascript root objects and import them into the __builtin__ namespace or something. I would expect any serious problems would involve identifier scope or exception handling, language qualities very much tied to the bytecode interpreter framework. On 12 Aug 2006 at 10:09, Armin Rigo wrote:
Hi Lenard,
On Fri, Aug 11, 2006 at 06:50:31PM -0700, Lenard Lindstrom wrote:
Maybe javascript can compile to Python byte code.
No, that wouldn't work. The two language's object models are different, as is always the case between dynamic languages, so you cannot just map the syntax of one to the bytecode of the other.
Lenard Lindstrom <len-l@telus.net>
Hi Lenard, On Sat, Aug 12, 2006 at 11:54:42AM -0700, Lenard Lindstrom wrote:
I must be missing something here. Isn't Python's object model defined by the type objects themselves?
I was thinking about the way all objects work; the type objects only define methods and properties of their instances, but not *what* a method or a property is. In Python, the "object model" contains a lot of logic about what special method calls are triggered by "a+b", and how an attribute lookup is performed. In JavaScript the object model is far simpler: it is described by a number of internal properties that objects have, like [[Prototype]], and how these properties are used in various operations like attribute lookup. It needs to be done, but that's not necessarily difficult indeed. It's possible that other aspects will be more irksome. Nevertheless, it means that you can never really reuse the bytecode of one dynamic language to implement another one, because the "object models" are typically quite different, in the sense above. Most bytecodes - GETATTR, BINARY_ADD, etc. - do things in Python that are completely unrelated to what the equivalent bytecode would need to do in JavaScript, even before we consider type objects. A bientot, Armin
Hi Leonardo, On Fri, Aug 11, 2006 at 06:59:00PM -0300, Leonardo Santagada wrote:
I would like to enter Summer of Pypy with my proposal to make a javascript interpreter. I had a chat with some nice people in #pypy and they thought it was a good idea.
Nice plan :-)
So I checked the code and started looking at what should/can do on 2 months of work ( I don't know if there is this limitation on time).
Not necessarily, but the proposal should have a timeline and your calendar should allow you to put "reasonable" amounts of work on it.
I am a litle lost with all the code from pypy and the idea of making another interpreter so I am posting here my ideas and I am specting your feedback.
What do you think I need to do? define a javascript virtual machine or do simple direct interpretation of the source?
I'm not completely clear about the difference between a simple direct interpreter and a virtual machine. JavaScript like Python is a language where the main work is in getting the execution model and the object model right. For the object model I mean building the Python classes that support the various kinds of JavaScript objects -- "kind" as in the [[Class]] internal property -- with all the other internal properties and methods; and then making the pre-built objects and prototypes and functions. It's ok to leave out some parts of the library of pre-built objects for the Summer of PyPy's duration. (This part corresponds to PyPy's "object spaces".) For the execution model, as you note, you need to start with an interpreter. It would interpret bytecodes that you are free to invent; I guess they would directly correspond to JavaScript syntax elements. (What I mean by execution model also includes things like function and method calls, and how to fit built-in functions.) (This part is documented under the name "bytecode interpreter" in PyPy.) (JavaScript ref.: http://www.ecma-international.org/publications/standards/Ecma-262.htm)
Should I use the parser defined on pyparsing (this one seems really nice) or write one manually?
I'm not sure about this. Our tokenizer and parser are definitely meant to be reusable, but I'm not exactly sure how :-/ I think there is a way to recompile the tables in pytokenize.py. The parser loads a grammar dynamically, so that's simpler. My 2 cents, though, is that you don't start the work here; if you know about another JavaScript parser that produces some data that is easy to feed to Python, it would be a good start. (Ultimately, we really need a parser written in RPython, but it's ok to leave this out of the Summer of PyPy proposal.) A bientot, Armin
participants (3)
-
Armin Rigo
-
Lenard Lindstrom
-
Leonardo Santagada