void Scm_Init_gauche__izc(void) { ScmModule *mod; /* Register this DSO to Gauche */ SCM_INIT_EXTENSION(izc); /* Create the module if it doesn't exist yet. */ mod = SCM_MODULE(SCM_FIND_MODULE("izc", TRUE)); /* Create the foreign pointer class <mqueue-cpp>. The flag SCM_FOREIGN_POINTER_KEEP_IDENTITY makes Gauche to keep one-to-one mapping between the foreign object pointer (MQueue*) and its wrapping ScmObj. With this flag, you can assume that when mqueue_cleanup is called, no other ScmForeignPointer object is pointing to the same MQueue*, thus you can delete it safely. */ CSintClass = Scm_MakeForeignPointerClass(mod, "<csint>", csint_print, csint_cleanup, SCM_FOREIGN_POINTER_KEEP_IDENTITY|SCM_FOREIGN_POINTER_MAP_NULL); CSintArrayClass = Scm_MakeForeignPointerClass(mod, "<csint-array>", csint_array_print, csint_array_cleanup, SCM_FOREIGN_POINTER_KEEP_IDENTITY|SCM_FOREIGN_POINTER_MAP_NULL); /* Register stub-generated procedures */ Scm_Init_izclib(mod); }
/*================================================================ * Initialization */ void Scm_Init_libgauche_glut(void) { ScmModule *mod; SCM_INIT_EXTENSION(libgauche_glut); mod = SCM_MODULE(SCM_FIND_MODULE("gl.glut", TRUE)); Scm_Init_glut_lib(mod); /* Callback table */ ScmGlutCallbackTable = Scm_MakeHashTableSimple(SCM_HASH_EQV, 0); /* Glut built-in fonts */ #define DEFFONT(name) Scm_DefineConst(mod, SCM_SYMBOL(SCM_INTERN(#name)), makeGlutFont(name)) /* Stroke font constants (use these in GLUT program). */ DEFFONT(GLUT_STROKE_ROMAN); DEFFONT(GLUT_STROKE_MONO_ROMAN); /* Bitmap font constants (use these in GLUT program). */ DEFFONT(GLUT_BITMAP_9_BY_15); DEFFONT(GLUT_BITMAP_8_BY_13); DEFFONT(GLUT_BITMAP_TIMES_ROMAN_10); DEFFONT(GLUT_BITMAP_TIMES_ROMAN_24); #if (GLUT_API_VERSION >= 3) DEFFONT(GLUT_BITMAP_HELVETICA_10); DEFFONT(GLUT_BITMAP_HELVETICA_12); DEFFONT(GLUT_BITMAP_HELVETICA_18); #endif }
void Scm_Init_gauche_sdl_collide(void) { ScmModule *mod; SCM_INIT_EXTENSION(gauche_sdl_collide); mod = SCM_MODULE(SCM_FIND_MODULE("sdl.collide", TRUE)); Scm_Init_sdl_collidelib(mod); Scm_Init_collide_type(mod); }
void Scm_Init_gauche_rsvg(void) { ScmModule *mod; SCM_INIT_EXTENSION(gauche_rsvg); mod = SCM_MODULE(SCM_FIND_MODULE("cairo.rsvg", TRUE)); Scm_Init_rsvglib(mod); Scm_Init_rsvg_type(mod); }
void Scm_Init_nnvector(void) { ScmModule *mod; /* Register this DSO to Gauche */ SCM_INIT_EXTENSION(gauche_nnvector); /* Create the module if it doesn't exist yet. */ mod = SCM_MODULE(SCM_FIND_MODULE("nnvector", TRUE)); /* Register stub-generated procedures */ Scm_Init_nnvector_lib(mod); Scm_Init_nnvector_type(mod); }
void Scm_Init_gauche_clipboard(void) { ScmModule *mod; /* Register this DSO to Gauche */ SCM_INIT_EXTENSION(gauche_clipboard); /* Create the module if it doesn't exist yet. */ mod = SCM_MODULE(SCM_FIND_MODULE("clipboard", TRUE)); /* Register stub-generated procedures */ Scm_Init_gauche_clipboardlib(mod); }
ScmObj Scm_Init_qnb(void) { ScmModule *mod; /* Register this DSO to Gauche */ SCM_INIT_EXTENSION(qnb); /* Create the module if it doesn't exist yet. */ mod = SCM_MODULE(SCM_FIND_MODULE("qnb", TRUE)); /* Register stub-generated procedures */ Scm_Init_qnblib(mod); }
void Scm_Init_gauche_cv_objdetect(void) { ScmModule *mod; /* Register this DSO to Gauche */ SCM_INIT_EXTENSION(gauche_cv_objdetect); /* Create the module if it doesn't exist yet. */ mod = SCM_MODULE(SCM_FIND_MODULE("cv.objdetect", TRUE)); /* Register stub-generated procedures */ Scm_Init_cv_objdetectlib(mod); Scm_Init_objdetect_type(mod); }
/*========================================================== * Initialization */ void Scm_Init_gauche_glgd(void) { ScmModule *mod; SCM_INIT_EXTENSION(gauche_glgd); mod = SCM_MODULE(SCM_FIND_MODULE("gtk.glgd", TRUE)); Scm_InitBuiltinClass(SCM_CLASS_GLGD_NODE, "<glgd-node>", NULL, sizeof(Scm_GLGDNode), mod); Scm_InitBuiltinClass(SCM_CLASS_GLGD_LINK, "<glgd-link>", NULL, sizeof(Scm_GLGDLink), mod); Scm_InitBuiltinClass(SCM_CLASS_GLGD_GRAPH, "<glgd-graph>", NULL, sizeof(Scm_GLGDGraph), mod); Scm_Init_glgdlib(mod); }
ScmObj Scm_Init_graphics_gd(void) { const char *module_name = "graphics.gd"; ScmModule *mod; SCM_INIT_EXTENSION(graphics_gd); mod = SCM_MODULE(SCM_FIND_MODULE(module_name, TRUE)); GraphicsGdImageClass = Scm_MakeForeignPointerClass(mod, "<gd-image>", NULL, graphicsGdImageCleanUp, SCM_FOREIGN_POINTER_KEEP_IDENTITY|SCM_FOREIGN_POINTER_MAP_NULL); GraphicsGdFontClass = Scm_MakeForeignPointerClass(mod, "<gd-font>", NULL, graphicsGdFontCleanUp, SCM_FOREIGN_POINTER_KEEP_IDENTITY|SCM_FOREIGN_POINTER_MAP_NULL); sym_destroyed = SCM_INTERN("destroyed?"); Scm_Init_graphics_gdlib(mod); /* the following feature identifiers are available *after* loading. */ #ifdef GD_XPM Scm_AddFeature("gauche.ext.graphics.gd.xpm", module_name); #endif /* GD_XPM */ #ifdef GD_PNG Scm_AddFeature("gauche.ext.graphics.gd.png", module_name); #endif /* GD_PNG */ #ifdef GD_JPEG Scm_AddFeature("gauche.ext.graphics.gd.jpeg", module_name); #endif /* GD_JPEG */ #ifdef GD_GIF Scm_AddFeature("gauche.ext.graphics.gd.gif", module_name); #endif /* GD_GIF */ #ifdef GD_FREETYPE Scm_AddFeature("gauche.ext.graphics.gd.freetype", module_name); #endif /* GD_FREETYPE */ #ifdef GD_FONTCONFIG Scm_AddFeature("gauche.ext.graphics.gd.fontconfig", module_name); #endif /* GD_FONTCONFIG */ }
void Scm_Init_ggcnumextra() { ScmModule *module = SCM_MODULE(SCM_FIND_MODULE("ggc.numerical.extra", TRUE)); Scm_Init_ggc_numerical_extra(module); }
int Scm_Compare(ScmObj x, ScmObj y) { /* Shortcut for typical case */ if (SCM_NUMBERP(x) && SCM_NUMBERP(y)) { if (SCM_COMPNUMP(x) || SCM_COMPNUMP(y)) { /* Scm_NumCmp can't compare complex numbers---it doesn't make mathematical sense. But Scm_Compare is used just to order items, it doesn't need to carry meaning. So here it goes. We follow srfi-114 spec. */ /* TODO: If we ever introduce exact compnums, we should use exact number first to compare, for Scm_GetDouble may lose precision. */ /* TODO: Handle NaN. */ double xr = Scm_RealPart(x); double yr = Scm_RealPart(y); if (xr < yr) return -1; if (xr > yr) return 1; double xi = Scm_ImagPart(x); double yi = Scm_ImagPart(y); if (xi < yi) return -1; if (xi > yi) return 1; return 0; } else { return Scm_NumCmp(x, y); } } if (SCM_STRINGP(x) && SCM_STRINGP(y)) return Scm_StringCmp(SCM_STRING(x), SCM_STRING(y)); if (SCM_CHARP(x) && SCM_CHARP(y)) return SCM_CHAR_VALUE(x) == SCM_CHAR_VALUE(y)? 0 : SCM_CHAR_VALUE(x) < SCM_CHAR_VALUE(y)? -1 : 1; /* Set cx, cy here, for we may jump to distinct_types later. */ ScmClass *cx = Scm_ClassOf(x); ScmClass *cy = Scm_ClassOf(y); /* srfi-114 default comparator behaviors*/ /* () is the smallest of all */ if (SCM_NULLP(x)) return (SCM_NULLP(y)? 0 : -1); if (SCM_NULLP(y)) return (SCM_NULLP(x)? 0 : 1); if (SCM_PAIRP(x)) { if (SCM_PAIRP(y)) { ScmObj px = x; ScmObj py = y; while (SCM_PAIRP(px) && SCM_PAIRP(py)) { int r = Scm_Compare(SCM_CAR(px), SCM_CAR(py)); if (r != 0) return r; px = SCM_CDR(px); py = SCM_CDR(py); } return Scm_Compare(px, py); } goto distinct_types; } if (SCM_FALSEP(x)) { if (SCM_FALSEP(y)) return 0; if (SCM_TRUEP(y)) return -1; goto distinct_types; } if (SCM_TRUEP(x)) { if (SCM_FALSEP(y)) return 1; if (SCM_TRUEP(y)) return 0; goto distinct_types; } if (Scm_SubtypeP(cx, cy)) { if (cy->compare) return cy->compare(x, y, FALSE); } else if (Scm_SubtypeP(cy, cx)) { if (cx->compare) return cx->compare(x, y, FALSE); } if (cx == cy) { /* x and y are of the same type, and they can't be ordered. */ Scm_Error("can't compare %S and %S", x, y); } distinct_types: /* x and y are of distinct types. Follow the srfi-114 rule: () < pairs < booleans < chars < strings < symbols < numbers < vectors < bytevectors < others Note that we already eliminated NULL. */ #define ELIMINATE(pred) \ do { \ if pred(x) return -1; \ if pred(y) return 1; \ } while (0) ELIMINATE(SCM_PAIRP); ELIMINATE(SCM_BOOLP); ELIMINATE(SCM_CHARP); ELIMINATE(SCM_STRINGP); ELIMINATE(SCM_SYMBOLP); ELIMINATE(SCM_NUMBERP); ELIMINATE(SCM_VECTORP); /* To conform srfi-114, we must order u8vector first. For the consistency, we use this order: u8 < s8 < u16 < s16 < u32 < s32 < u64 < s64 < f16 < f32 < f64 Unfortunately this doesn't match the order of ScmUVectorType, so we need some tweak. */ if (SCM_UVECTORP(x)) { if (SCM_UVECTORP(y)) { int tx = Scm_UVectorType(Scm_ClassOf(x)); int ty = Scm_UVectorType(Scm_ClassOf(y)); if (tx/2 < ty/2) return -1; if (tx/2 > ty/2) return 1; if (tx < SCM_UVECTOR_F16) { /* x and y are either sNvector and uNvector with the same N. The odd one is uNvector. */ return (tx%2)? -1:1; } else { return (tx<ty)? -1:1; } } return -1; /* y is other, so x comes first. */ } else if (SCM_UVECTORP(y)) { return 1; /* x is other, so y comes first. */ } /* Now we have two objects of different types, both are not the types defined the order in srfi-114. To achieve better stability, we first compare the name of the classes and the names of their defining modules; if they are still the same, we fall back to compare addresses. Note: Addresses and defining modules may be changed when the class is redefined. */ ScmObj nx = cx->name; ScmObj ny = cy->name; int nr = Scm_Compare(nx, ny); if (nr != 0) return nr; ScmObj mx = cx->modules; ScmObj my = cy->modules; while (SCM_PAIRP(mx) && SCM_PAIRP(my)) { SCM_ASSERT(SCM_MODULEP(SCM_CAR(mx)) && SCM_MODULEP(SCM_CAR(my))); int r = Scm_Compare(SCM_MODULE(SCM_CAR(mx))->name, SCM_MODULE(SCM_CAR(my))->name); if (r != 0) return r; mx = SCM_CDR(mx); my = SCM_CDR(my); } if (SCM_PAIRP(mx)) return -1; if (SCM_PAIRP(my)) return 1; if (cx < cy) return -1; else return 1; }