#!/bin/sh

# environment variables:
# * ISQUICK: 1 = skip valgrind and run natively
# * NOREGEXP: 1 = don't compile regexp support

JS="${1-br0.js}"
O=`dirname $(readlink -f "$0")`
BIN="$O/js0"
ARGS=""
[ -n "$NOREGEXP" ] && ARGS="$ARGS -DNOREGEXP"
./gcc-warn.sh -O2 -g vm.c run.c -o $BIN $ARGS &&

{
  if [ "$#" = 0 ]; then
    cd ../br
  else
    true
  fi &&
  if [ -n "$ISQUICK" ]; then
    $BIN "$JS"
  else
    valgrind \
      --leak-check=full \
      --show-leak-kinds=all \
      --num-callers=30 \
      --malloc-fill=0xaa \
      --free-fill=0x55 \
      --redzone-size=256 \
      --read-var-info=yes \
      --expensive-definedness-checks=yes \
      --merge-recursive-frames=10 \
      --track-origins=yes \
      --partial-loads-ok=no \
      $BIN "$JS"
  fi
}
