#!/bin/sh

COMPILE_MODE=$1
SRC=$2

# expand the schant scheme compiler source

if [ $COMPILE_MODE = int ]; then
  cat $SRC/includes.h $SRC/defs.h $SRC/dcls.h \
      $SRC/forwards.c $SRC/misc.c $SRC/primitives.c \
      $SRC/select.c $SRC/stack.c $SRC/vector.c $SRC/integer.c \
      $SRC/construct.c $SRC/predicate.c $SRC/replace.c \
      $SRC/hash.c $SRC/gc.c \
      $SRC/symbol.c $SRC/string.c $SRC/numstring.c \
      $SRC/isnumber.c $SRC/gettok.c $SRC/read.c $SRC/atomlist.c $SRC/char.c \
      $SRC/printnumber.c $SRC/print.c \
      $SRC/ops.c $SRC/number.c \
      $SRC/asm.c $SRC/resource.c \
      $SRC/exec_arith.c $SRC/exec.c $SRC/exec_end.c \
      $SRC/initdw.c $SRC/initextra.c $SRC/init.c \
      $SRC/main.c \
      >x.c
elif [ $COMPILE_MODE = bigfloat8 ]; then # bigfloat with 8 digits
  cat $SRC/includes.h $SRC/math/defs8.h $SRC/math/defs.h $SRC/defs2.h \
      $SRC/dcls.h $SRC/dcls2.h $SRC/math/dcls.h \
      $SRC/forwards.c  $SRC/misc.c \
      $SRC/math/dcls.c $SRC/math/math.c $SRC/math/init.c \
      $SRC/primitives2.c \
      $SRC/select.c $SRC/stack.c $SRC/vector.c \
      $SRC/integer.c $SRC/construct.c $SRC/predicate.c $SRC/replace.c \
      $SRC/hash.c $SRC/gc.c \
      $SRC/symbol.c $SRC/string.c $SRC/numstring2.c \
      $SRC/isnumber2.c $SRC/gettok.c $SRC/read.c $SRC/atomlist.c $SRC/char.c \
      $SRC/printnumber2.c \
      $SRC/print.c $SRC/number2.c $SRC/ops2.c $SRC/number.c \
      $SRC/asm.c $SRC/resource.c \
      $SRC/exec_arith2.c $SRC/exec.c $SRC/exec2.c $SRC/exec_end.c \
      $SRC/initdw.c $SRC/init2.c $SRC/init3.c $SRC/init.c \
      $SRC/main.c \
      >x.c
else # bigfloat with 12 digits
  cat $SRC/includes.h $SRC/math/defs12.h $SRC/math/defs.h $SRC/defs2.h \
      $SRC/dcls.h $SRC/dcls2.h $SRC/math/dcls.h \
      $SRC/forwards.c  $SRC/misc.c \
      $SRC/math/dcls.c $SRC/math/math.c $SRC/math/init.c \
      $SRC/primitives2.c \
      $SRC/select.c $SRC/stack.c $SRC/vector.c \
      $SRC/integer.c $SRC/construct.c $SRC/predicate.c $SRC/replace.c \
      $SRC/hash.c $SRC/gc.c \
      $SRC/symbol.c $SRC/string.c $SRC/numstring2.c \
      $SRC/isnumber2.c $SRC/gettok.c $SRC/read.c $SRC/atomlist.c $SRC/char.c \
      $SRC/printnumber2.c \
      $SRC/print.c $SRC/number2.c $SRC/ops2.c $SRC/number.c \
      $SRC/asm.c $SRC/resource.c \
      $SRC/exec_arith2.c $SRC/exec.c $SRC/exec2.c $SRC/exec_end.c \
      $SRC/initdw.c $SRC/init2.c $SRC/init3.c $SRC/init.c \
      $SRC/main.c \
      >x.c
fi

mv x.c xxx

# modify cells size and stack size initialization

#NCELLS=2097152 # 0x00200000
NCELLS=10000000
#TWICE_NCELLS=4194304 # 0x00400000
TWICE_NCELLS=20000000 # 0x00400000
STACK_SIZE=50000

sed -e "s/NCELLS 50000/NCELLS $NCELLS/g" \
    -e "s/TWICE_NCELLS 100000/TWICE_NCELLS $TWICE_NCELLS/g" \
    -e "s/n_cells = NCELLS/n_cells = $NCELLS/g" \
    -e "s/stacksize = 2000/stacksize = $STACK_SIZE/g" \
  xxx >x.c
rm xxx

if [ $COMPILE_MODE = int ]; then
  echo schant-int
elif [ $COMPILE_MODE = bigfloat8 ]; then # bigfloat with 8 digits
  echo schant-bigfloat8
else # bigfloat with 12 digits
  echo schant-bigfloat12
fi
