<commit_before>.. image:: https://travis-ci.org/WebAssembly/sexpr-wasm-prototype.svg?branch=master
    :target: https://travis-ci.org/WebAssembly/sexpr-wasm-prototype
    :alt: Build Status

sexpr-wasm
==========

Translates from WebAssembly `s-expressions
<https://github.com/WebAssembly/spec>`_ to `v8-native-prototype
<https://github.com/WebAssembly/v8-native-prototype>`_ bytecode.

Cloning
-------

Clone as normal, but don't forget to update/init submodules as well::

  $ git clone https://github.com/WebAssembly/sexpr-wasm-prototype
  $ git submodule update --init

This will fetch the v8-native-prototype repo, which is needed for some tests.

Building
--------

Building just sexpr-wasm::

  $ make
  mkdir out
  cc -Wall -Werror -g -c -o out/sexpr-wasm.o src/sexpr-wasm.c
  cc -Wall -Werror -g -c -o out/wasm-parse.o src/wasm-parse.c
  cc -Wall -Werror -g -c -o out/wasm-gen.o src/wasm-gen.c
  cc -o out/sexpr-wasm out/sexpr-wasm.o out/wasm-parse.o out/wasm-gen.o

If you make changes to src/hash.txt, you'll need to install gperf as well. On
Debian-based systems::

  $ sudo apt-get install gperf
  ...
  $ touch src/hash.txt
  $ make
  gperf --compare-strncmp --readonly-tables --struct-type src/hash.txt --output-file src/hash.h
  ...

Building v8-native-prototype
----------------------------

The v8-native-prototype lets you run the generated bytecode. Some of the tests
rely on this repo. To build it::

  $ scripts/build-d8.sh
  ...

When it is finished, there will be a d8 executable in the
``third_party/v8-native-prototype/v8/v8/out/Release`` directory.

Running
-------

First write some WebAssembly s-expressions::

  $ cat > test.wasm << HERE
  (module
    (export "test" 0)
    (func (result i32)
      (i32.add (i32.const 1) (i32.const 2))))
  HERE

Then run sexpr-wasm to build v8-native-prototype bytecode::<commit_msg>update README.rst<commit_after>.. image:: https://travis-ci.org/WebAssembly/sexpr-wasm-prototype.svg?branch=master
    :target: https://travis-ci.org/WebAssembly/sexpr-wasm-prototype
    :alt: Build Status

sexpr-wasm
==========

Translates from WebAssembly `s-expressions
<https://github.com/WebAssembly/spec>`_ to `v8-native-prototype
<https://github.com/WebAssembly/v8-native-prototype>`_ bytecode.

Cloning
-------

Clone as normal, but don't forget to update/init submodules as well::

  $ git clone https://github.com/WebAssembly/sexpr-wasm-prototype
  $ git submodule update --init

This will fetch the v8-native-prototype and spec repos, which are needed for
some tests.

Building
--------

Building just sexpr-wasm::

  $ make
  mkdir out
  cc -Wall -Werror -g -c -o out/sexpr-wasm.o src/sexpr-wasm.c
  cc -Wall -Werror -g -c -o out/wasm-parse.o src/wasm-parse.c
  cc -Wall -Werror -g -c -o out/wasm-gen.o src/wasm-gen.c
  cc -o out/sexpr-wasm out/sexpr-wasm.o out/wasm-parse.o out/wasm-gen.o

If you make changes to src/wasm-keywords.gperf, you'll need to install gperf as
well. On Debian-based systems::

  $ sudo apt-get install gperf
  ...
  $ touch src/wasm-keywords.gperf
  $ make
  gperf --compare-strncmp --readonly-tables --struct-type src/wasm-keywords.gperf --output-file src/wasm-keywords.h
  ...

Building v8-native-prototype
----------------------------

The v8-native-prototype lets you run the generated bytecode. Some of the tests
rely on this repo. To build it::

  $ scripts/build-d8.sh
  ...

When it is finished, there will be a d8 executable in the
``third_party/v8-native-prototype/v8/v8/out/Release`` directory.

You can also download a prebuilt version (the same one used to test on Travis)
by running the download-d8.sh script::

  $ scripts/download-d8.sh
  ...

This downloads the d8 executable into the ``out`` directory. The test runner
will look here if there is no d8 executable in the
``third_party/v8-native-prototype/v8/v8/out/Release`` directory.

Running
-------

First write some WebAssembly s-expressions::

  $ cat > test.wasm << HERE
  (module
    (export "test" 0)
    (func (result i32)
      (i32.add (i32.const 1) (i32.const 2))))
  HERE

Then run sexpr-wasm to build v8-native-prototype bytecode::
{'fraction_non_alphanumeric': 0.1475609756097561, 'fraction_numerical': 0.012439024390243903, 'mean_word_length': 2.9470644850818095, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, 'https://': 10, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5055707', 'n_tokens_mistral': 1478, 'n_tokens_neox': 1419, 'n_words': 410}