/*****
 * builtin.h
 * Tom Prince 2004/08/25
 *
 * Initialize builtins.
 *****/
#ifndef BUILTIN_H
#define BUILTIN_H

#include "vm.h"
#include "types.h"
#include "arrayop.h"
#include "exp.h"

namespace trans {

class tenv;
class venv;

// The base environments for built-in types and functions
void base_tenv(tenv &);
void base_venv(venv &);

extern const types::formal noformal;

// Add a function with one or more default arguments.
varEntry *addFunc(venv &ve, vm::bltin f, types::ty *result, symbol name,
                  types::formal f1=noformal, types::formal f2=noformal,
                  types::formal f3=noformal, types::formal f4=noformal,
                  types::formal f5=noformal, types::formal f6=noformal,
                  types::formal f7=noformal, types::formal f8=noformal,
                  types::formal f9=noformal, types::formal fA=noformal,
                  types::formal fB=noformal, types::formal fC=noformal,
                  types::formal fD=noformal, types::formal fE=noformal,
                  types::formal fF=noformal, types::formal fG=noformal,
                  types::formal fH=noformal, types::formal fI=noformal);

// Register an open-signature builtin together with a pair of custom call-site
// handlers.  The handlers (declared as member-function pointers on callExp)
// are invoked from callExp::trans / callExp::getType after the call has been
// resolved to this open-signature entry.  `runtimeFn` is the bltin associated
// with the venv entry; for handlers that always emit their own runtime call
// (the typical pattern), it is never actually invoked.  If `takesNames` is
// true, calls with named arguments also resolve to this entry and the handler
// must interpret the names itself.
void addOpenBuiltinFunc(venv &ve, vm::bltin runtimeFn,
                        absyntax::callExp::CustomHandlers handlers,
                        types::ty *result, symbol name,
                        bool takesNames=false);

// Adds standard functions for a newly added types.
void addArrayOps(venv &ve, types::array *t);

#ifdef HAVE_LIBGSL
types::record *getGSLModule();
void GSLrngFree();
#endif

} //namespace trans

namespace run {
extern double infinity;

void single(vm::stack *Stack);
void arrayDeleteHelper(vm::stack *Stack);

// Used by to optimize conditional jumps.
extern const vm::bltin intLess;
extern const vm::bltin intGreater;
}

#endif //BUILTIN_H
