Skip to content

Instantly share code, notes, and snippets.

Revisions

  1. @rohit-nsit08 rohit-nsit08 created this gist Apr 2, 2011.
    216 changes: 216 additions & 0 deletions JavaScript Compiler. final version
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,216 @@
    NAME: Rohit Jangid

    EMAIL ID: rohit.nsit08@gmail.com

    GOOGLE ID: rohit.nsit08

    OTHER CONTACT INFO:
    Irc nick-name on #parrot channel: rohit_nsit08
    skype id : rohit_nsit08

    PROJECT TITLE: JavaScript on Parrot

    ABSTRACT:
    The project is based on implementing a JavaScript compiler using JavaScript. The existing
    compiler projects like cafe/jasper would be used for front-end. Reusing already built code
    will be of utmost priority, which requires use of parser generators like Jison or PEG.js etc.
    The primary attempt is to customize the backend (code generator) of cafe to make it generate
    parrot friendly PIR/PBC code. Cafe project is most likely to provide much needed compiler
    infrastructure.

    BENEFITS TO THE PARROT VM AND OPEN SOURCE COMMUNITY:
    JavaScript is one of the most popular and preferred scripting language among users and hackers
    on the internet. All such people will be benefited with its inclusion in parrot list of interpreters.
    Successful implementation of JavaScript compiler would encourage JavaScript developer community in
    improvising the same. It is important since all the present browsers are JavaScript enabled but
    there are very few command line tools available for it. There are compilers already available in
    JavaScript like 'Rhino' from Mozilla, which is written in java and is one of the frequently used tool
    in this regard. However, Rhino has performance issues and limitations with size of byte code generated
    by it (which I faced myself). Currently ‘narwhal’ is using 'rhino'. 'node.js', another compiler, which
    uses much better Google’s v8 engine is built in C++. But there are no such compilers in JavaScript.
    Though there exists a JavaScript compiler on parrot "ECMASCRIPT", but is not very usable in its current
    form due to lack of people workingon it and its dependencies on old NQP and PGE.
    In short, there is a need for a better, fast, optimized command-line JavaScript compiler with better
    features. So we can offer this service on parrot, which will contribute to the Open-Source Community also.
    Since good tools are already available in JavaScript like parser generators and interpreters, bootstrapped
    compiler becomes a very good option to start with. So, here is my proposal on how i will proceed and
    develop a bootstrapped JavaScript compiler written entirely in JavaScript.

    DELIVERABLES:
    A bootstrapped JavaScript compiler on Parrot.
    Test-suite with examples using rosella and ‘jspec’ testing framework
    An efficient build infrastructure compatible with major plateform
    Project documentation that will help future developers to carry on work further.

    PROJECT DETAILS:

    1. The project is based on bootstrapping concept to make a JavaScript -in- JavaScript on
    parrot compiler.

    2. The primary attempt will be to transform the code generator of already available
    JavaScript parser “cafe” (which is using jison to generate parser) to generate PIR/PBC
    code.

    3. I will use already available compiler/interpreter node.js which is using Google’s v8
    engine or ‘narwhal’ which is using ‘rhino’ engine as bootstrap compiler (stage 0
    compiler) to generate parrot friendly PIR/PBC code.

    4. I will compile generated PIR code in parrot to get a independent stand-alone
    executable compiler, this will become our STAGE 1 compiler which will be able to compile
    its own source code.

    5. Further modifications will be made to Stage 1 compiler by adding support for modules
    written in other languages. Any modification to stage 1 will result in a feature rich
    stage 2 compiler.

    6. At this stage, we’ll be having a running JavaScript compiler on parrot platform.

    7. Necessary optimizations and tests would be conducted to ensure stable working of stage
    1 compiler.

    8. If all goes well, I will attempt to transform original AST into parrots PAST OBJECT so
    that I can use optimizations and other facilities available on Parrot..

    9. Modification in the generated source code would be done followed by compiling it in
    itself in cycles for further improvements to get desired performance.

    10.Test-suite will be implemented in two parts:
    Part1: Before we have stage 1 ready, testing will be implemented using rosella
    test.pbc
    Part2: After stage 1, we’ll be having a running JavaScript compiler so now we can
    attempt to use ‘jspec’ testing framework for this stage, in combination with rosella.

    11. For documentation purpose, jsdoc has been chosen as it is open source with lots of
    organizations already using it for their JavaScript documentation.
    My current status: I’m currently experimenting on node.js, cafe, and jison combination. I
    have done good study of cafe and working to get PIR code generating back-end. I am in
    touch with author of cafe, jison and node.js to get more knowledge of their tools. I am
    also studying code base of winxed which is a JavaScript like language already implemented
    on parrot.

    PROJECT SCHEDULE:

    March 28 – April 25: Work on project details, search for loop holes to ensure proper
    understanding of project and getting familiar with parrot organization. Study ECMAScript,
    JavaScript language specification. Study test-suits and testing framework, getting
    familiar to use Github.
    Target: To get acquaint with the in-depth details of the project, and testing framework.

    April 26 – May 15: Complete all the work on cafe, jison and nodejs resolve all issues if
    any. Study the code generator’s code in café.
    Target: Set up a working environment prepared to go for stage 1 compiler.
    Milestone 0: All groundwork would be finished by this stage so as to start the actual
    coding. Discuss detailed plan of project, backup policy with the mentor. Finalize stage 0
    compiler.

    University Exams: <tentative dates> May 16 – May 31 <absent during this time>

    Summer Vacations from August 1

    ACTUAL CODING STARTS:

    Week 1) June 1-June6: Work on cafe backend, transform code generator to emit code in
    PIR/PBC.
    Milestone 1: Work started on backend with few tests to check correctness.

    Week 2) June 7-June 13: Carry on with backend code, work on improving the code structure
    and add more tests.
    Milestone 2: Compiler is able to generate PIR code, <may require further improvements>.

    Week 3) June 14-June 22: Run the generated PIR code on Parrot, remove errors if any from
    the week 2 project. Build an executable and get the stage 1 compiler ready.
    Milestone 3: A running (may be with error or warnings) stage 1 compiler on parrot and
    successful compilation of ‘jspec’ or any other JavaScript program to test the compiler.

    Week 4) June 23-June 29: Remove all the errors from the compiler, add test- suite, and
    test for crash and failures. Debug and test work done. Start documentation up to this
    stage.
    Milestone 4: An improved stage 1 compiler on parrot.

    Week 5) June 30-July 6: Will attempt to transform parrot’s PAST from original AST. This
    will be done in parallel to the testing of stage 1 compiler. Add more test suites if
    necessary.
    Milestone 5: More code with test-suites, and complete documentation till stage 1.

    Week 6) July 7-july 13: Discuss PAST status with mentor and decide how to proceed
    further, make changes in plan if needed.
    Milestone 6: PAST may or may not be introduced to compiler, depending on discussion with
    mentor and plan out for the next week.

    Week 7) July 14-July 20: Work again on PAST with better strategy, more tests to be added
    in the compiler, study about stage 2 features and how to implement them
    Milestone 7: Most probably a compiler with PAST, if failure occurs , stick to backup
    policy.

    Week 8) July 21-July 27: project compilation upto stage 1 , complete any backlogs , this
    time is for compensate for any unknown break during previous weeks , complete
    documentation , finish final test suite till this stage ,
    Milestone 8: successful project finished upto stage 1 .

    Week 9) July 28-August 3: start hacking on stage 1 compiler ,to add special parrot
    features like cross library communication , start reading standard compilers api. Discuss
    with mentors about the necessary features that can be implemented
    Milestone 9: features to be added decided ,Work started on one choosen feature.

    Week 10) August 4-August 10 : work on the decided features , do necessary study. Keep
    discussing project improvements with mentor ,start to think about test suite for new
    compiler (JSpec or any other), Discuss about the new test-suite with mentor and start
    making tests
    Milestone 10: clear about the features and how to implement them , atleast one feature
    ready for compilation.

    Week 11)August 11-August 17: Create more tests and test the features if any added , work
    on more features . test the compiler for all previous stages to ensure everything is
    intact and working perfectly if not , stick to backup policy and stop further work and
    finish main compiler (stage 1) to ensure it’s working perfectly .
    MileStone 11: atleast 2 or 3 features added in compiler, work completed on test-suite. A
    working compiler existing on parrot.

    Week 12) August 18-August 22: Wind up the project , complete documentation work , improve
    code structure ,confirm project status with the mentor .
    Milestone 12: a complete successful GSOC project

    REFERENCES AND LIKELY MENTORS:

    Discussed project idea with
    Whiteknight
    Dukeleto
    (* irc nick-names)

    PROBLEM RESOLUTION

    Clear the project details before the actual coding to avoid confusion later.
    Keep in touch with mentor and the authors of the tools and libraries if used any.
    Make Backup policy in such a way to keep focus on imp goals to avoid major problems that
    can stop project’s progress.
    Generate useful tests to reduce errors and crashes.
    Testing at various stages of compiler design to ensure sustained development and in case
    of any problem, i will be able to go to previous stage.

    BACKUP PLAN
    Test the code after every significant change in source code to ensure stable
    configuration.
    In case of failures in stage 2 compiler , go back to stage 1 compiler and ensure it’s
    working perfectly , if not make it work and add more tests and get back to where we left
    the project.
    Build compiler in stages and sub-stages so that moving back and forth from one sub stage
    to other is possible in case of sudden failure.
    Highest priority is the working stage 1 compiler , stage 2 and inclusion of PAST will be
    attempted only after a stable stage 1 compiler.

    BIO:
    Hello,
    My name is Rohit Jangid, and I’m a computer science student from NSIT
    (http://www.nsit.ac.in) college, India. I’ve been programming from my school time and
    have a vast experience in various types of languages and platform . C/C++ , JavaScript
    and Java are my primary languages, have also worked extensively in j2ee technology like
    Servlets and jsp for web-applications. I’m open source promoter and infact love working
    on Linux. I’m very dedicated towards my work and can learn new things very quickly and I
    believe that makes me a good candidate to work on this project. Though I am new to parrot
    and compiler design, I’ve done extensive study in this subject while interacting with
    Parrot members on irc. Our semester course for next semester contains “compiler design”
    as a subject also, This is also one of the motivating factor that attracts me to my
    project. I’m familiar with basic project development on Linux and version control system
    like bazaar,github and launchpad etc, I’m pursuing a graduate course and currently in 3rd
    year, and have necessary documents that can prove my admission and that makes me an
    eligible student for gsoc , I’ll clarify the legal requirements if needed.