/* Generated by genstub.  Do not edit. */
#define LIBGAUCHE_BODY 
#include <gauche.h>

#line 35 "exclib.stub"
#include <gauche/class.h>
#include <gauche/exception.h>

#if defined(__CYGWIN__) || defined(GAUCHE_WINDOWS)
#define SCM_CGEN_CONST /*empty*/
#else
#define SCM_CGEN_CONST const
#endif
static SCM_CGEN_CONST struct scm__scRec {
  ScmString d1004[9];
} scm__sc = {
  {   /* ScmString d1004 */
      SCM_STRING_CONST_INITIALIZER("rewind-before", 13, 13),
      SCM_STRING_CONST_INITIALIZER("with-error-handler", 18, 18),
      SCM_STRING_CONST_INITIALIZER("current-exception-handler", 25, 25),
      SCM_STRING_CONST_INITIALIZER("with-exception-handler", 22, 22),
      SCM_STRING_CONST_INITIALIZER("raise", 5, 5),
      SCM_STRING_CONST_INITIALIZER("report-error", 12, 12),
      SCM_STRING_CONST_INITIALIZER("condition?", 10, 10),
      SCM_STRING_CONST_INITIALIZER("condition-has-type?", 19, 19),
      SCM_STRING_CONST_INITIALIZER("make-compound-condition", 23, 23),
  },
};
static struct scm__rcRec {
  ScmObj d1003[1];
} scm__rc = {
  {   /* ScmObj d1003 */
    SCM_UNBOUND,
  },
};
static ScmObj exclib_with_error_handler(ScmObj *SCM_FP, int SCM_ARGCNT, void *data_)
{
  ScmObj handler_scm;
  ScmObj handler;
  ScmObj thunk_scm;
  ScmObj thunk;
  ScmObj rewind_before_scm = SCM_FALSE;
  int rewind_before;
  ScmObj SCM_OPTARGS = SCM_ARGREF(SCM_ARGCNT-1);
  SCM_ENTER_SUBR("with-error-handler");
  handler_scm = SCM_ARGREF(0);
  handler = (handler_scm);
  thunk_scm = SCM_ARGREF(1);
  thunk = (thunk_scm);
  if (Scm_Length(SCM_OPTARGS) % 2)
    Scm_Error("keyword list not even: %S", SCM_OPTARGS);
  while (!SCM_NULLP(SCM_OPTARGS)) {
    if (SCM_EQ(SCM_CAR(SCM_OPTARGS), scm__rc.d1003[0])) {
      rewind_before_scm = SCM_CADR(SCM_OPTARGS);
    }
    else Scm_Warn("unknown keyword %S", SCM_CAR(SCM_OPTARGS));
    SCM_OPTARGS = SCM_CDDR(SCM_OPTARGS);
  }
  if (!SCM_BOOLP(rewind_before_scm)) Scm_Error("boolean required, but got %S", rewind_before_scm);
  rewind_before = SCM_BOOL_VALUE(rewind_before_scm);
  {
{
ScmObj SCM_RESULT;

#line 44 "exclib.stub"
if (!(SCM_PROCEDURE_TAKE_NARG_P(handler,1))){{
Scm_Error("error handler must take at least 1 argument, but got %S",handler);}}

#line 47 "exclib.stub"
if (!(SCM_PROCEDURE_THUNK_P(thunk))){{
Scm_Error("thunk required, but got %S",thunk);}}

#line 49 "exclib.stub"
if (rewind_before){
SCM_RESULT=(Scm_VMWithGuardHandler(handler,thunk));} else {
SCM_RESULT=(Scm_VMWithErrorHandler(handler,thunk));}
SCM_RETURN(SCM_OBJ_SAFE(SCM_RESULT));
}
  }
}

static SCM_DEFINE_SUBR(exclib_with_error_handler__STUB, 2, 1,SCM_OBJ(&scm__sc.d1004[1]),exclib_with_error_handler, NULL, NULL);

static ScmObj exclib_current_exception_handler(ScmObj *SCM_FP, int SCM_ARGCNT, void *data_)
{
  SCM_ENTER_SUBR("current-exception-handler");
  {
{
ScmObj SCM_RESULT;

#line 55 "exclib.stub"
SCM_RESULT=((Scm_VM())->exceptionHandler);
SCM_RETURN(SCM_OBJ_SAFE(SCM_RESULT));
}
  }
}

static SCM_DEFINE_SUBRX(exclib_current_exception_handler__STUB, 0, 0,0, SCM_OBJ(&scm__sc.d1004[2]),SCM_SUBR_IMMEDIATE_ARG, exclib_current_exception_handler, NULL, NULL);

static ScmObj exclib_with_exception_handler(ScmObj *SCM_FP, int SCM_ARGCNT, void *data_)
{
  ScmObj handler_scm;
  ScmObj handler;
  ScmObj thunk_scm;
  ScmObj thunk;
  SCM_ENTER_SUBR("with-exception-handler");
  handler_scm = SCM_ARGREF(0);
  handler = (handler_scm);
  thunk_scm = SCM_ARGREF(1);
  thunk = (thunk_scm);
  {
{
ScmObj SCM_RESULT;
SCM_RESULT=(Scm_VMWithExceptionHandler(handler,thunk));
SCM_RETURN(SCM_OBJ_SAFE(SCM_RESULT));
}
  }
}

static SCM_DEFINE_SUBR(exclib_with_exception_handler__STUB, 2, 0,SCM_OBJ(&scm__sc.d1004[3]),exclib_with_exception_handler, NULL, NULL);

static ScmObj exclib_raise(ScmObj *SCM_FP, int SCM_ARGCNT, void *data_)
{
  ScmObj exception_scm;
  ScmObj exception;
  SCM_ENTER_SUBR("raise");
  exception_scm = SCM_ARGREF(0);
  exception = (exception_scm);
  {
{
ScmObj SCM_RESULT;
SCM_RESULT=(Scm_Raise(exception));
SCM_RETURN(SCM_OBJ_SAFE(SCM_RESULT));
}
  }
}

static SCM_DEFINE_SUBR(exclib_raise__STUB, 1, 0,SCM_OBJ(&scm__sc.d1004[4]),exclib_raise, NULL, NULL);

static ScmObj exclib_report_error(ScmObj *SCM_FP, int SCM_ARGCNT, void *data_)
{
  ScmObj exception_scm;
  ScmObj exception;
  SCM_ENTER_SUBR("report-error");
  exception_scm = SCM_ARGREF(0);
  exception = (exception_scm);
  {
Scm_ReportError(exception);
SCM_RETURN(SCM_UNDEFINED);
  }
}

static SCM_DEFINE_SUBR(exclib_report_error__STUB, 1, 0,SCM_OBJ(&scm__sc.d1004[5]),exclib_report_error, NULL, NULL);

static ScmObj exclib_conditionP(ScmObj *SCM_FP, int SCM_ARGCNT, void *data_)
{
  ScmObj obj_scm;
  ScmObj obj;
  SCM_ENTER_SUBR("condition?");
  obj_scm = SCM_ARGREF(0);
  obj = (obj_scm);
  {
{
int SCM_RESULT;
SCM_RESULT=(SCM_CONDITIONP(obj));
SCM_RETURN(SCM_MAKE_BOOL(SCM_RESULT));
}
  }
}

static SCM_DEFINE_SUBR(exclib_conditionP__STUB, 1, 0,SCM_OBJ(&scm__sc.d1004[6]),exclib_conditionP, NULL, NULL);

static ScmObj exclib_condition_has_typeP(ScmObj *SCM_FP, int SCM_ARGCNT, void *data_)
{
  ScmObj c_scm;
  ScmObj c;
  ScmObj k_scm;
  ScmObj k;
  SCM_ENTER_SUBR("condition-has-type?");
  c_scm = SCM_ARGREF(0);
  c = (c_scm);
  k_scm = SCM_ARGREF(1);
  k = (k_scm);
  {
{
int SCM_RESULT;
SCM_RESULT=(Scm_ConditionHasType(c,k));
SCM_RETURN(SCM_MAKE_BOOL(SCM_RESULT));
}
  }
}

static SCM_DEFINE_SUBR(exclib_condition_has_typeP__STUB, 2, 0,SCM_OBJ(&scm__sc.d1004[7]),exclib_condition_has_typeP, NULL, NULL);

static ScmObj exclib_make_compound_condition(ScmObj *SCM_FP, int SCM_ARGCNT, void *data_)
{
  ScmObj conditions_scm;
  ScmObj conditions;
  SCM_ENTER_SUBR("make-compound-condition");
  conditions_scm = SCM_ARGREF(SCM_ARGCNT-1);
  conditions = (conditions_scm);
  {
{
ScmObj SCM_RESULT;
SCM_RESULT=(Scm_MakeCompoundCondition(conditions));
SCM_RETURN(SCM_OBJ_SAFE(SCM_RESULT));
}
  }
}

static SCM_DEFINE_SUBRX(exclib_make_compound_condition__STUB, 0, 1,0, SCM_OBJ(&scm__sc.d1004[8]),SCM_SUBR_IMMEDIATE_ARG, exclib_make_compound_condition, NULL, NULL);

static ScmObj thread_exception_allocate(ScmClass* klass,ScmObj initargs){{
#line 78 "exclib.stub"
{ScmThreadException* e=SCM_ALLOCATE(ScmThreadException,klass);
SCM_SET_CLASS(e,klass);
(e)->thread=(NULL);
(e)->data=(SCM_UNDEFINED);
return (SCM_OBJ(e));}}}
static void thread_exception_print(ScmObj obj,ScmPort* port,ScmWriteContext* ctx){{
#line 86 "exclib.stub"
{ScmClass* k=SCM_CLASS_OF(obj);ScmThreadException* exc=
SCM_THREAD_EXCEPTION(obj);ScmObj cname=
Scm__InternalClassName(k);
if (SCM_UNDEFINEDP((exc)->data)){
Scm_Printf(port,"#<%A %S>",cname,SCM_OBJ_SAFE((exc)->thread));} else {
Scm_Printf(port,"#<%A %S %S>",cname,SCM_OBJ_SAFE((exc)->thread),
(exc)->data);}}}}
static void uncaught_exception_print(ScmObj obj,ScmPort* port,ScmWriteContext* ctx){{
#line 96 "exclib.stub"
{ScmThreadException* exc=SCM_THREAD_EXCEPTION(obj);
Scm_Printf(port,"#<uncaught-exception in thread %S: %S>",
SCM_OBJ_SAFE((exc)->thread),(exc)->data);}}}
static void terminated_thread_print(ScmObj obj,ScmPort* port,ScmWriteContext* ctx){{
#line 102 "exclib.stub"
{ScmThreadException* exc=SCM_THREAD_EXCEPTION(obj);
Scm_Printf(port,"#<terminated-thread-exception: %S terminated by %S>",
SCM_OBJ_SAFE((exc)->thread),(exc)->data);}}}
static ScmClass *thread_exception_cpa[] = {
   SCM_CLASS_STATIC_PTR(Scm_ThreadExceptionClass),
   SCM_CLASS_STATIC_PTR(Scm_ConditionClass),
   SCM_CLASS_STATIC_PTR(Scm_TopClass),
   NULL
 };
static ScmClass *Scm_ThreadExceptionClass_CPL[] = {
  SCM_CLASS_STATIC_PTR(Scm_ConditionClass),
  SCM_CLASS_STATIC_PTR(Scm_TopClass),
  NULL
};
SCM_DEFINE_BUILTIN_CLASS(Scm_ThreadExceptionClass, thread_exception_print, NULL, NULL, thread_exception_allocate, Scm_ThreadExceptionClass_CPL);

static ScmObj Scm_ThreadExceptionClass_thread_GET(ScmObj OBJARG)
{
  ScmThreadException* obj = SCM_THREAD_EXCEPTION(OBJARG);
  return SCM_OBJ_SAFE(obj->thread);
}

static void Scm_ThreadExceptionClass_thread_SET(ScmObj OBJARG, ScmObj value)
{
  ScmThreadException* obj = SCM_THREAD_EXCEPTION(OBJARG);
  if (!SCM_VMP(value)) Scm_Error("ScmVM* required, but got %S", value);
  obj->thread = SCM_VM(value);
}

static ScmClassStaticSlotSpec Scm_ThreadExceptionClass__SLOTS[] = {
  SCM_CLASS_SLOT_SPEC("thread", Scm_ThreadExceptionClass_thread_GET, Scm_ThreadExceptionClass_thread_SET),
  SCM_CLASS_SLOT_SPEC_END()
};

SCM_DEFINE_BUILTIN_CLASS(Scm_JoinTimeoutExceptionClass, thread_exception_print, NULL, NULL, thread_exception_allocate, thread_exception_cpa);

SCM_DEFINE_BUILTIN_CLASS(Scm_AbandonedMutexExceptionClass, thread_exception_print, NULL, NULL, thread_exception_allocate, thread_exception_cpa);

static ScmObj Scm_AbandonedMutexExceptionClass_mutex_GET(ScmObj OBJARG)
{
  ScmThreadException* obj = SCM_THREAD_EXCEPTION(OBJARG);
  return SCM_OBJ_SAFE(obj->data);
}

static void Scm_AbandonedMutexExceptionClass_mutex_SET(ScmObj OBJARG, ScmObj value)
{
  ScmThreadException* obj = SCM_THREAD_EXCEPTION(OBJARG);
  obj->data = (value);
}

static ScmClassStaticSlotSpec Scm_AbandonedMutexExceptionClass__SLOTS[] = {
  SCM_CLASS_SLOT_SPEC("mutex", Scm_AbandonedMutexExceptionClass_mutex_GET, Scm_AbandonedMutexExceptionClass_mutex_SET),
  SCM_CLASS_SLOT_SPEC_END()
};

SCM_DEFINE_BUILTIN_CLASS(Scm_TerminatedThreadExceptionClass, terminated_thread_print, NULL, NULL, thread_exception_allocate, thread_exception_cpa);

static ScmObj Scm_TerminatedThreadExceptionClass_terminator_GET(ScmObj OBJARG)
{
  ScmThreadException* obj = SCM_THREAD_EXCEPTION(OBJARG);
  return SCM_OBJ_SAFE(obj->data);
}

static void Scm_TerminatedThreadExceptionClass_terminator_SET(ScmObj OBJARG, ScmObj value)
{
  ScmThreadException* obj = SCM_THREAD_EXCEPTION(OBJARG);
  obj->data = (value);
}

static ScmClassStaticSlotSpec Scm_TerminatedThreadExceptionClass__SLOTS[] = {
  SCM_CLASS_SLOT_SPEC("terminator", Scm_TerminatedThreadExceptionClass_terminator_GET, Scm_TerminatedThreadExceptionClass_terminator_SET),
  SCM_CLASS_SLOT_SPEC_END()
};

SCM_DEFINE_BUILTIN_CLASS(Scm_UncaughtExceptionClass, uncaught_exception_print, NULL, NULL, thread_exception_allocate, thread_exception_cpa);

static ScmObj Scm_UncaughtExceptionClass_reason_GET(ScmObj OBJARG)
{
  ScmThreadException* obj = SCM_THREAD_EXCEPTION(OBJARG);
  return SCM_OBJ_SAFE(obj->data);
}

static void Scm_UncaughtExceptionClass_reason_SET(ScmObj OBJARG, ScmObj value)
{
  ScmThreadException* obj = SCM_THREAD_EXCEPTION(OBJARG);
  obj->data = (value);
}

static ScmClassStaticSlotSpec Scm_UncaughtExceptionClass__SLOTS[] = {
  SCM_CLASS_SLOT_SPEC("reason", Scm_UncaughtExceptionClass_reason_GET, Scm_UncaughtExceptionClass_reason_SET),
  SCM_CLASS_SLOT_SPEC_END()
};

void Scm_Init_exclib(ScmModule *mod){

  scm__rc.d1003[0] = Scm_MakeKeyword(SCM_STRING(SCM_OBJ(&scm__sc.d1004[0]))); /* rewind-before */
  Scm_MakeBinding(SCM_MODULE(mod), SCM_SYMBOL(SCM_INTERN("with-error-handler")), SCM_OBJ(&exclib_with_error_handler__STUB), 0);
  Scm_MakeBinding(SCM_MODULE(mod), SCM_SYMBOL(SCM_INTERN("current-exception-handler")), SCM_OBJ(&exclib_current_exception_handler__STUB), 0);
  Scm_MakeBinding(SCM_MODULE(mod), SCM_SYMBOL(SCM_INTERN("with-exception-handler")), SCM_OBJ(&exclib_with_exception_handler__STUB), 0);
  Scm_MakeBinding(SCM_MODULE(mod), SCM_SYMBOL(SCM_INTERN("raise")), SCM_OBJ(&exclib_raise__STUB), 0);
  Scm_MakeBinding(SCM_MODULE(mod), SCM_SYMBOL(SCM_INTERN("report-error")), SCM_OBJ(&exclib_report_error__STUB), 0);
  Scm_MakeBinding(SCM_MODULE(mod), SCM_SYMBOL(SCM_INTERN("condition?")), SCM_OBJ(&exclib_conditionP__STUB), 0);
  Scm_MakeBinding(SCM_MODULE(mod), SCM_SYMBOL(SCM_INTERN("condition-has-type?")), SCM_OBJ(&exclib_condition_has_typeP__STUB), 0);
  Scm_MakeBinding(SCM_MODULE(mod), SCM_SYMBOL(SCM_INTERN("make-compound-condition")), SCM_OBJ(&exclib_make_compound_condition__STUB), 0);
  Scm_InitBuiltinClass(&Scm_ThreadExceptionClass, "<thread-exception>", Scm_ThreadExceptionClass__SLOTS, TRUE, SCM_MODULE(mod));
  Scm_InitBuiltinClass(&Scm_JoinTimeoutExceptionClass, "<join-timeout-exception>", NULL, TRUE, SCM_MODULE(mod));
  Scm_InitBuiltinClass(&Scm_AbandonedMutexExceptionClass, "<abandoned-mutex-exception>", Scm_AbandonedMutexExceptionClass__SLOTS, TRUE, SCM_MODULE(mod));
  Scm_InitBuiltinClass(&Scm_TerminatedThreadExceptionClass, "<terminated-thread-exception>", Scm_TerminatedThreadExceptionClass__SLOTS, TRUE, SCM_MODULE(mod));
  Scm_InitBuiltinClass(&Scm_UncaughtExceptionClass, "<uncaught-exception>", Scm_UncaughtExceptionClass__SLOTS, TRUE, SCM_MODULE(mod));
}
