1 / 12

Hop - A platform for distributed Web applications

Hop - A platform for distributed Web applications. Akash Khasgiwala Anup Talwalkar Andrew Weller - Team 5, TopCoders Report 3 April 29, 2009. Compiling Scheme to JavaScript Florian Loitsch Inria Sophia Antipolis Manuel Serrano Inria Sophia Antipolis

chessa
Download Presentation

Hop - A platform for distributed Web applications

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Hop - A platform for distributed Web applications Akash Khasgiwala Anup Talwalkar Andrew Weller - Team 5, TopCoders Report 3 April 29, 2009

  2. Compiling Scheme to JavaScript Florian Loitsch Inria Sophia Antipolis Manuel Serrano Inria Sophia Antipolis http://hop.inria.fr/usr/local/lib/hop/1.10.2/weblets/home/articles/scheme2js/article.html

  3. JavaScript and Scheme • Using Scheme instead of JavaScript should impose no performance penalty. • Scheme and JavaScript must be tightly integrated.

  4. Scheme vs. JavaScript • Some shared features of scheme and javaScript - • types are dynamically checked, • functions are first class citizens, • lexical scoping, • automatic memory management, • an eval function, which allows one to compile and run code at run-time, and • n-ary and var-arg functions with an apply primitive that allows to indirectly call these functions on a list or array of arguments.

  5. The differences • Lisp-style syntax to C-like syntax • Data types • booleans to booleans. • functions to JavaScript functions. • numbers to JavaScript numbers. The empty list is represented by null. • vectors to JavaScript Arrays. • characters to the "class" sc_Char, holding a JavaScript string of length 1. • strings to a new JavaScript "class", sc_String. • symbols to strings. • JavaScript's typing rules are less restrictive than Scheme's rules. • Optimization

  6. Flow Control • Direct mapping is impossible. • Two popular solutions are trampolines and Henry Baker's "Cheney on the M.T.A." • For now Scm2Js just tries to compile tail-recursive calls into iterative JavaScript statements.

  7. Scm2Js tries to compile tail-recursive calls into iterative JavaScript statements. • Example: (let loop ((x 1)) (if (> x 10) 'done (loop (+ x 1)))) • is compiled as: var res = undefined; var x = 1; while (true) { if (> x 10) res = "done"; else { x = x + 1; continue; } break; }

  8. JavaScript Integration • Scm2Js provides a complete JavaScript-Scheme interface. • That is JavaScript code can access Scheme variables and call Scheme functions, and inversely Scheme code can use JavaScript values. • Eg - Scheme strings are translated into a new class sc_String. If a Scheme string should be used as JavaScript string a call to string->symbol is hence necessary, whereas a JavaScript string can be converted to a Scheme string by the means of symbol->string • this-extension added to ease the integration of Scheme functions in the context of JavaScript. • js-field and js-field-set! • -to retrieve or set fields of Js Objects. x.y.z = a.b would be: (js-field-set! (js-field x 'y) 'z (js-field a 'b)) (set! x.y.z a.b)

  9. Hop Integration • The SCM2JS compiler has been developed to compile Hop client code to Java-Script, bigloo • The Scm2Js compiler lets us replace JavaScript with Scheme in Hop programs.

  10. Demo

  11. References • Compiling Scheme to JavaScript Florian Loitsch Inria Sophia Antipolis Manuel Serrano Inria Sophia Antipolis http://hop.inria.fr/usr/local/lib/hop/1.10.2/weblets/home/articles/scheme2js/article.html • Scheme • The Revised^5 Report on Scheme (R5RS).<http://schemers.org/Documents/Standards/R5RS//HTML/> • The Revised^6 Report on Scheme (R6RS).<http://www.r6rs.org/> • Bigloo • Bigloo user manual.<http://www-sop.inria.fr/mimosa/fp/Bigloo/doc/bigloo.html>

More Related