#include <assert.h>
#include <stdarg.h>
#include "native_calls.h"

// find all native call declarations
#include "types.h"
#include <fcntl.h>
#include <math.h>
#include <unistd.h>
#include <sys/mman.h>
#include "blockingio.h"
#include "clock.h"
#include "engine.h"
#include "eventmanager.h"
#include "sigiomanager.h"
#include "waitmanager.h"
#include "mem.h"
#include "native_interface.h"
#include "native_helpers.h"
#include "nativeScheduling.h"
#include "timer.h"
#include "systemproperties.h"
#include "signalmonitor.h"
#include "doselect.h"
#include <sys/stat.h>
#include <sys/types.h>

/* Note the angle quotes.  They ensure that we start searching from
 * the start of the include path
 */
#include <app_native_calls.h>

jlong invoke_native(int code, ...)
{
#define POP()     (va_arg(ap, jvalue))
#define POP_W()   (va_arg(ap, jwide))
#define PUSH_P(V) return ((jvalue) V).jint
#define PUSH_R(V) return ((jvalue) V).jint
#define PUSH_W(V) return ((jwide) V).jlong

  va_list ap;
  va_start(ap, code);
  switch (code) {
#include "native_calls.gen"
  default:
    fprintf(stderr, "unknown native call %d\n", code);
    abort();
  }
  return 0;
}
