Wednesday, December 03, 2014

chibi-scheme and native client

Getting chibi-scheme to work with Native Client was easier than I expected.  I used
  • chibi-scheme 0.7
  • pepper-37
  • Chrome 40
  • on OS X 10.9.5
I unpacked the chibi-scheme tarball and the Native Client SDK into ~/Source, and ran naclsdk update to grab the latest stable toolchain.  Then,

export NACL_SDK_ROOT=$HOME/Source/nacl_sdk/pepper_37
export CHIBI_ROOT=$HOME/Source/chibi-scheme-0.7

make SEXP_USE_DL=0 \
  CC=$NACL_SDK_ROOT/toolchain/mac_pnacl/bin/pnacl-clang++ \
  CFLAGS="-I$NACL_SDK_ROOT/include -I$NACL_SDK_ROOT/include/pnacl" \
  LDFLAGS="-L$NACL_SDK_ROOT/lib/pnacl/Release -lnacl_io -lppapi -lpthread" \
  EXE=.pexe \

You don't need chibi-scheme-static.pexe, but you do need the .o files.  Don't run make clean in this directory!

Next up, integrating chibi-scheme into a pnacl module, and then accessing that from a web page.  Here, I simply copied and adapted $NACL_SDK_ROOT/getting_started/part1: Makefile and code.  It shouldn't be too hard to adapt the example's index.html to use the new module; at minimum, modify the example's page to say

    <div id="listener">
      <script type="text/javascript">
        var listener = document.getElementById('listener');
        listener.addEventListener('load', moduleDidLoad, true);
        listener.addEventListener('message', handleMessage, true);

      <embed id="pn1"
             width=0 height=0
             type="application/x-pnacl" />

Run make serve, and visit http://localhost:5103/ in Chrome to load the page and module.  Pop open a console and type

HelloTutorialModule.postMessage('(+ 2 3)');

You'll probably want to modify the page to add an input field for your input and a p tag or textarea for the result of your evaluated form.  Here's what I started with: index.html.

No comments: