4
* Copyright (c) 2006 KOGURO, Naoki (naoki@koguro.net)
6
* Permission is hereby granted, free of charge, to any person
7
* obtaining a copy of this software and associated
8
* documentation files (the "Software"), to deal in the
9
* Software without restriction, including without limitation
10
* the rights to use, copy, modify, merge, publish, distribute,
11
* sublicense, and/or sell copies of the Software, and to
12
* permit persons to whom the Software is furnished to do so,
13
* subject to the following conditions:
15
* The above copyright notice and this permission notice shall
16
* be included in all copies or substantial portions of the
19
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
20
* KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
21
* WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
22
* PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
23
* OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
24
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
25
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
26
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28
* $Id: ffi.c 233 2006-05-03 15:58:37Z naoki $
32
#include <gauche/class.h>
33
#include <gauche/exception.h>
37
static ScmObj objc_error_allocate(ScmClass *klass, ScmObj initargs);
38
static void objc_error_print(ScmObj objc_error, ScmPort *port, ScmWriteContext *ctx);
40
static ScmClass *default_cpl[] = {
41
SCM_CLASS_STATIC_PTR(Scm_TopClass), NULL
44
SCM_DEFINE_BASE_CLASS(Scm_ObjCErrorClass, ScmObjCError,
45
objc_error_print, NULL, NULL, objc_error_allocate,
48
static ScmObj objc_error_allocate(ScmClass *klass, ScmObj initargs)
50
ScmObjCError *err = SCM_ALLOCATE(ScmObjCError, klass);
51
SCM_SET_CLASS(err, klass);
52
err->name = SCM_FALSE;
53
err->reason = SCM_FALSE;
55
SCM_RETURN(SCM_OBJ(err));
58
static void objc_error_print(ScmObj obj, ScmPort *port, ScmWriteContext *ctx)
60
Scm_Printf(port, "#<objc-error %A (%A)>"
61
, SCM_OBJC_ERROR(obj)->name, SCM_OBJC_ERROR(obj)->reason);
64
static ScmObj objc_error_name_get(ScmObjCError *err)
66
SCM_RETURN(err->name);
69
static ScmObj objc_error_reason_get(ScmObjCError *err)
71
SCM_RETURN(err->reason);
74
static ScmClassStaticSlotSpec objc_error_slots[] = {
75
SCM_CLASS_SLOT_SPEC("name", objc_error_name_get, NULL),
76
SCM_CLASS_SLOT_SPEC("reason", objc_error_reason_get, NULL),
80
ScmObj Scm_MakeObjCError(ScmObj name, ScmObj reason)
82
ScmObj e = objc_error_allocate(SCM_CLASS_OBJC_ERROR, SCM_NIL);
83
SCM_OBJC_ERROR(e)->name = name;
84
SCM_OBJC_ERROR(e)->reason = reason;
89
void Scm_Init_ObjCError(ScmModule *mod)
91
Scm_InitStaticClass(&Scm_ObjCErrorClass, "<objc-error>", mod, objc_error_slots, 0);