Friday, July 5, 2013

PEBL in a browser: 1. Emscripten basics

PEBL was born before web browsers were very capable and prior was always targeted at running directly on users computers in compiled code.  But with the emergence of many new devices (tablets, phones, etc.) and an acceptance of new ways of running experiments (Mechanical turk), it is apparent that if PEBL could run from the web, it would open up a lot of opportunities.  An important one is for demonstration tasks for use in classroom settings.



This seemed like a foolish dream until the development of emscripten.  Emscripten is a cool technology driven by Mozilla that will allow you to compile c++ code into javascript which will then run in a web browser.  How it works is that it uses the Clang/LVVM compiler c++ compiler, which itself first compiles c++ to a 'low-level virtual machine' code.  Emscripten takes the LLVM code and compiles it into javascript, with options for optimizing speed that supposedly can be close (i.e., maybe 200% of) native speed.  Because we aren't number crunching, this should be fine for PEBL, so I have started looking at what it would take to port PEBL to emscripten.

The real kicker is that emscripten supports SDL by default, which means that most of the display and hopefully even keyboard stuff will be transparent. 


There are a number of obstacles that will need to be overcome.  I'll make a list of a few here:
  • Will PEBL really compile and run, with its use of the many complex libraries, templates, flex/bison generated code, a fairly low-level counted-pointer reference system, hardware interactions, etc.?
  • How can we make PEBL asynchronous?  The recursive evaluator which steps through a PEBL experiment provides no easy way to cede control to the browser.  This will likely be the obstacle that prevents success.
  • How can we handle file I/O? Javascript has limited support of file operations.  Will it be possible to save data after an experiment runs?
  • How can we easily support running/selecting experiments for users
These are  a few of the initial obstacles that I will be tackling this summer.  Stay tuned here for updates as they are handled.
Post a Comment