Beispiel #1
0
static kbool_t HelloWorld_PackupNameSpace(KonohaContext *kctx, kNameSpace *ns, int option, KTraceInfo *trace)
{
	/* Class Definition */
	/* If you want to create Generic class like Array<T>, see konoha.map package */
	KDEFINE_CLASS defPerson = {0};
	SETSTRUCTNAME(defPerson, Person);
	defPerson.cflag     = kClass_Final;
	defPerson.init      = Person_Init;
	defPerson.p         = Person_p;
	defPerson.reftrace  = Person_Reftrace;
	defPerson.free      = Person_Free;
	KonohaClass *PersonClass = KLIB kNameSpace_DefineClass(kctx, ns, NULL, &defPerson, trace);

	/* You can define methods with the following procedures. */
	int TY_Person = PersonClass->typeId;
	int FN_x = FN_("x");
	int FN_y = FN_("y");
	KDEFINE_METHOD MethodData[] = {
		_Public, _F(Person_new), TY_Person, TY_Person, MN_("new"), 2, TY_String, FN_x, TY_int, FN_y,
		_Public, _F(Person_say), TY_String, TY_Person, MN_("say"), 0,
		DEND, /* <= sentinel */
	};
	KLIB kNameSpace_LoadMethodData(kctx, ns, MethodData, trace);

	/* You can define constant variable with the following procedures. */
	KDEFINE_INT_CONST IntData[] = {
		{"NARUTO_AGE", TY_int, 18},
		{} /* <= sentinel */
	};
	KLIB kNameSpace_LoadConstData(kctx, ns, KonohaConst_(IntData), false/*isOverride*/, trace);
	return true;
}
Beispiel #2
0
static kbool_t iterator_PackupNameSpace(KonohaContext *kctx, kNameSpace *ns, int option, KTraceInfo *trace)
{
	KRequireKonohaCommonModule(trace);
	if(CT_Iterator == NULL) {
		kparamtype_t IteratorParam = {TY_Object};
		KDEFINE_CLASS defIterator = {0};
		SETSTRUCTNAME(defIterator, Iterator);
		defIterator.cflag  = CFLAG_Iterator;
		defIterator.init   = Iterator_Init;
		defIterator.cparamsize  = 1;
		defIterator.cParamItems = &IteratorParam;

		CT_Iterator = KLIB kNameSpace_DefineClass(kctx, ns, NULL, &defIterator, trace);
		CT_StringIterator = CT_p0(kctx, CT_Iterator, TY_String);
		CT_GenericIterator = CT_p0(kctx, CT_Iterator, TY_0);
	}

	KDEFINE_METHOD MethodData[] = {
		_Public, _F(Iterator_hasNext), TY_boolean, TY_Iterator, MN_("hasNext"), 0,
		_Public, _F(Iterator_next), TY_0, TY_Iterator, MN_("next"), 0,
		_Public, _F(Array_toIterator),  TY_GenericIterator, TY_Array, MN_("toIterator"), 0,
		_Public, _F(String_toIterator), TY_StringIterator, TY_String, MN_("toIterator"), 0,
		DEND,
	};
	KLIB kNameSpace_LoadMethodData(kctx, ns, MethodData, trace);
	return true;
}
Beispiel #3
0
static kbool_t bytes_PackupNameSpace(KonohaContext *kctx, kNameSpace *ns, int option, KTraceInfo *trace)
{
	KRequireKonohaCommonModule(trace);
	//KImportPackageSymbol(ns, "cstyle", "$SingleQuotedChar", trace);
	if(KClass_Bytes == NULL) {
		KDEFINE_CLASS defBytes = {0};
		SETSTRUCTNAME(defBytes, Bytes);
		defBytes.cflag   = KClassFlag_Final;
		defBytes.free    = kBytes_Free;
		defBytes.init    = kBytes_Init;
		defBytes.format       = kBytes_format;
		KClass_Bytes = KLIB kNameSpace_DefineClass(kctx, ns, NULL, &defBytes, trace);
	}
	int FN_index = KFieldName_("index");
	int FN_c     = KFieldName_("c");
	int FN_size  = KFieldName_("size");
	KDEFINE_METHOD MethodData[] = {
		_Public,     _F(Bytes_new),     KType_Bytes,  KType_Bytes, KMethodName_("new"),     1, KType_Int, FN_size,
		_Public|_Im, _F(Bytes_getSize), KType_Int,    KType_Bytes, KMethodName_("getSize"), 0,
		_Public|_Im, _F(Bytes_get),     KType_Int,    KType_Bytes, KMethodName_("get"),     1, KType_Int, FN_index,
		_Public,     _F(Bytes_Set),     KType_void,   KType_Bytes, KMethodName_("set"),     2, KType_Int, FN_index, KType_Int, FN_c,
		_Public,     _F(Bytes_SetAll),  KType_void,   KType_Bytes, KMethodName_("setAll"),  1, KType_Int, FN_c,
		_Public|_Im|_Coercion, _F(String_toBytes), KType_Bytes, KType_String, KMethodName_To(KType_Bytes),   0,
		//_Public|_Im|_Coercion, _F(Bytes_toString), KType_String, KType_Bytes,  KMethodName_To(KType_String),  0,
		//_Public|_Const, _F(Bytes_encodeTo),   KType_Bytes,  KType_Bytes,  KMethodName_("encodeTo"),    1, KType_String, FN_encoding,
		//_Public|_Const, _F(Bytes_decodeFrom),   KType_String, KType_Bytes,  KMethodName_("decodeFrom"),    1, KType_String, FN_encoding,
		_Public, _F(String_new_fromBytes_withDefaultDecode),      KType_String, KType_String, KMethodName_("new"), 1, KType_Bytes, KFieldName_("ba"),
		_Public, _F(String_new_fromBytes_withSpecifiedDecode),    KType_String, KType_String, KMethodName_("new"), 2, KType_Bytes, KFieldName_("ba"), KType_String, KFieldName_("charset"),
		_Public, _F(String_new_fromSubBytes_withDefaultDecode),   KType_String, KType_String, KMethodName_("new"), 3, KType_Bytes, KFieldName_("ba"), KType_Int,    KFieldName_("offset"), KType_Int, KFieldName_("length"),
		_Public, _F(String_new_fromSubBytes_withSpecifiedDecode), KType_String, KType_String, KMethodName_("new"), 4, KType_Bytes, KFieldName_("ba"), KType_Int,    KFieldName_("offset"), KType_Int, KFieldName_("length"), KType_String, KFieldName_("charset"),
		DEND,
	};
	KLIB kNameSpace_LoadMethodData(kctx, ns, MethodData, trace);
	return true;
}
Beispiel #4
0
static kbool_t Libevent_PackupNameSpace(KonohaContext *kctx, kNameSpace *ns, int option, KTraceInfo *trace)
{
	/* Class Definition */
	KDEFINE_CLASS defLibevent = {0};
	SETSTRUCTNAME(defLibevent, Libevent);
	defLibevent.cflag     = KClassFlag_Final;
	defLibevent.init      = Libevent_Init;
	defLibevent.free      = Libevent_Free;
	KClass *LibeventClass = KLIB kNameSpace_DefineClass(kctx, ns, NULL, &defLibevent, trace);

	int KType_Libevent = LibeventClass->typeId;

	KDEFINE_METHOD MethodData[] = {
		_Public, _F(Libevent_new), KType_Libevent, KType_Libevent, KMethodName_("new"), 0,
		_Public, _F(Libevent_dispatch), KType_Libevent, KType_Libevent, KMethodName_("dispatch"), 0,
		_Public, _F(Libevent_event_add), KType_Int, KType_Libevent, KMethodName_("event_add"), 2, KType_Object, KFieldName_("timeval"),
		_Public, _F(Libevent_event_del), KType_Int, KType_Libevent, KMethodName_("event_del"), 1,



#ifdef	CUTCUT
		_Public, _F(Person_say), KType_String, KType_Person, KMethodName_("say"), 0,
#endif
		DEND, /* <= sentinel */
	};
	KLIB kNameSpace_LoadMethodData(kctx, ns, MethodData, trace);

	return true;
}
Beispiel #5
0
static void prototype_defineClass(KonohaContext *kctx, kNameSpace *ns, int option, KTraceInfo *trace)
{
	if(KClass_Prototype == NULL) {
		KDEFINE_CLASS defPrototype = {};
		defPrototype.structname = "Prototype",
		defPrototype.typeId = KTypeAttr_NewId,
		defPrototype.baseTypeId = KType_Object,
		defPrototype.format = kPrototype_format,
		KClass_Prototype = KLIB kNameSpace_DefineClass(kctx, ns, NULL, &defPrototype, trace);
	}
}
Beispiel #6
0
static kbool_t float_defineMethod(KonohaContext *kctx, kNameSpace *ns, KTraceInfo *trace)
{
	KRequireKonohaCommonModule(trace);
	if(KClass_Float == NULL) {
		KDEFINE_CLASS defFloat = {0};
		SETUNBOXNAME(defFloat, float);
		defFloat.cstruct_size = sizeof(kFloat);
		defFloat.cflag = KClassFlag_int;
		defFloat.init = kFloat_Init;
		defFloat.p     = kFloat_p;
		KClass_Float = KLIB kNameSpace_DefineClass(kctx, ns, NULL, &defFloat, trace);
	}
	int FN_x = KFieldName_("x");
	KDEFINE_METHOD MethodData[] = {
		_Public|_Const|_Im, _F(Float_opPlus), KType_float, KType_float, KMethodName_("+"), 0,
		_Public|_Const|_Im, _F(Float_opADD), KType_float, KType_float, KMethodName_("+"), 1, KType_float, FN_x,
		_Public|_Const|_Im, _F(Int_opADD), KType_float, KType_Int, KMethodName_("+"), 1, KType_float, FN_x,
		_Public|_Const|_Im, _F(Float_opSUB), KType_float, KType_float, KMethodName_("-"), 1, KType_float, FN_x,
		_Public|_Const|_Im, _F(Int_opSUB), KType_float, KType_Int, KMethodName_("-"), 1, KType_float, FN_x,
		_Public|_Const|_Im, _F(Float_opMUL), KType_float, KType_float, KMethodName_("*"), 1, KType_float, FN_x,
		_Public|_Im, _F(Float_opDIV), KType_float, KType_float, KMethodName_("/"), 1, KType_float, FN_x,
		_Public|_Const|_Im, _F(Float_opEQ),  KType_Boolean, KType_float, KMethodName_("=="), 1, KType_float, FN_x,
		_Public|_Const|_Im, _F(Float_opNEQ), KType_Boolean, KType_float, KMethodName_("!="), 1, KType_float, FN_x,
		_Public|_Const|_Im, _F(Float_opLT),  KType_Boolean, KType_float, KMethodName_("<"), 1, KType_float, FN_x,
		_Public|_Const|_Im, _F(Float_opLTE), KType_Boolean, KType_float, KMethodName_("<="), 1, KType_float, FN_x,
		_Public|_Const|_Im, _F(Float_opGT),  KType_Boolean, KType_float, KMethodName_(">"), 1, KType_float, FN_x,
		_Public|_Const|_Im, _F(Float_opGTE), KType_Boolean, KType_float, KMethodName_(">="), 1, KType_float, FN_x,
		_Public|_Const|_Im, _F(Int_opMUL), KType_float, KType_Int, KMethodName_("*"), 1, KType_float, FN_x,
		_Public|_Im, _F(Int_opDIV), KType_float, KType_Int, KMethodName_("/"), 1, KType_float, FN_x,
		_Public|_Const|_Im, _F(Int_opEQ),  KType_Boolean, KType_Int, KMethodName_("=="), 1, KType_float, FN_x,
		_Public|_Const|_Im, _F(Int_opNEQ), KType_Boolean, KType_Int, KMethodName_("!="), 1, KType_float, FN_x,
		_Public|_Const|_Im, _F(Int_opLT),  KType_Boolean, KType_Int, KMethodName_("<"), 1, KType_float, FN_x,
		_Public|_Const|_Im, _F(Int_opLTE), KType_Boolean, KType_Int, KMethodName_("<="), 1, KType_float, FN_x,
		_Public|_Const|_Im, _F(Int_opGT),  KType_Boolean, KType_Int, KMethodName_(">"), 1, KType_float, FN_x,
		_Public|_Const|_Im, _F(Int_opGTE), KType_Boolean, KType_Int, KMethodName_(">="), 1, KType_float, FN_x,

		_Public|_Const|_Im|_Coercion, _F(Float_toInt), KType_Int, KType_float, KMethodName_To(KType_Int), 0,
		_Public|_Const|_Im|_Coercion, _F(Int_toFloat), KType_float, KType_Int, KMethodName_To(KType_float), 0,
		_Public|_Const|_Im, _F(Float_toString), KType_String, KType_float, KMethodName_To(KType_String), 0,
		_Public|_Const|_Im, _F(String_toFloat), KType_float, KType_String, KMethodName_To(KType_float), 0,
		_Public|_Const|_Im, _F(Float_opMINUS), KType_float, KType_float, KMethodName_("-"), 0,
		DEND,
	};
	KLIB kNameSpace_LoadMethodData(kctx, ns, MethodData, trace);
	KDEFINE_FLOAT_CONST FloatData[] = {
		{"FLOAT_EPSILON", KType_float, DBL_EPSILON},
		{"Infinity", KType_float, INFINITY},
		{"NaN", KType_float, NAN},
		{NULL} /* sentinel */
	};
	KLIB kNameSpace_LoadConstData(kctx, ns, KConst_(FloatData), trace);
	return true;
}
Beispiel #7
0
static kbool_t regexp_defineMethod(KonohaContext *kctx, kNameSpace *ns, KTraceInfo *trace)
{
	if(CT_RegExp == NULL) {
		KDEFINE_CLASS RegExpDef = {
			STRUCTNAME(RegExp),
			.cflag = 0,
			.init = RegExp_Init,
			.free = RegExp_Free,
			.p    = RegExp_p,
		};
		CT_RegExp = KLIB kNameSpace_DefineClass(kctx, ns, NULL, &RegExpDef, trace);
	}
Beispiel #8
0
static KClassVar* kNameSpace_DefineClassName(KonohaContext *kctx, kNameSpace *ns, const char *text, size_t len)
{
	KDEFINE_CLASS defNewClass = {0};
	defNewClass.cflag       = 0;
	defNewClass.typeId      = KTypeAttr_NewId;
	defNewClass.baseTypeId  = KType_Object;
	defNewClass.superTypeId = KType_Object;
	defNewClass.init = Object_InitToMakeDefaultValueAsNull;

	kString *name = KLIB new_kString(kctx, GcUnsafe, text, len, StringPolicy_TEXT);
	KBaseTrace(trace);
	return (KClassVar *) KLIB kNameSpace_DefineClass(kctx, ns, name, &defNewClass, trace);
}
Beispiel #9
0
static kbool_t openssl_PackupNameSpace(KonohaContext *kctx, kNameSpace *ns, int option, KTraceInfo *trace)
{
	static const char *names[] = {
		"MD5",
		"SHA1",
	};
	KonohaClass *tbls[2];
	static KDEFINE_CLASS Def = {
			.structname = "",
			.typeId = TY_newid,
			.init = RawPtr_Init,
			.free = RawPtr_Free,
	};
#define TY_MD5  tbls[0]->typeId
#define TY_SHA1 tbls[1]->typeId
	int i;
	for (i = 0; i < 2; i++) {
		Def.structname = names[i];
		tbls[i] = KLIB kNameSpace_DefineClass(kctx, ns, NULL, &Def, trace);
	}

	int FN_x = FN_("x");
	KDEFINE_METHOD MethodData[] = {
		_P, _F(kMD5_Init),   TY_SHA1,   TY_MD5, MN_("new"), 0,
		_P, _F(kMD5_Update), TY_int,   TY_MD5, MN_("update"), 1, TY_String, FN_x,
		_P, _F(kMD5_Final),  TY_String, TY_MD5, MN_("final"), 0,
		_P, _F(kSHA1_Init),   TY_SHA1,   TY_SHA1, MN_("new"), 0,
		_P, _F(kSHA1_Update), TY_int,   TY_SHA1, MN_("update"), 1, TY_String, FN_x,
		_P, _F(kSHA1_Final),  TY_String, TY_SHA1, MN_("final"), 0,

		DEND,
	};
	KLIB kNameSpace_LoadMethodData(kctx, ns, MethodData, trace);
	return true;
}

static kbool_t openssl_ExportNameSpace(KonohaContext *kctx, kNameSpace *ns, kNameSpace *exportNS, int option, KTraceInfo *trace)
{
	return true;
}

KDEFINE_PACKAGE *openssl_Init(void)
{
	static KDEFINE_PACKAGE d = {
		KPACKNAME("openssl", "1.0"),
		.PackupNameSpace    = openssl_PackupNameSpace,
		.ExportNameSpace   = openssl_ExportNameSpace,
	};
	return &d;
}
Beispiel #10
0
static kbool_t kNameSpace_InitGlobalObject(KonohaContext *kctx, kNameSpace *ns, KTraceInfo *trace)
{
    if(ns->globalObjectNULL_OnList == NULL) {
        KDEFINE_CLASS defGlobalObject = {0};
        defGlobalObject.structname = "GlobalObject";
        defGlobalObject.typeId = TY_newid;
        defGlobalObject.cflag = kClass_Singleton|kClass_Final;
        defGlobalObject.cstruct_size = sizeof(kGlobalObject);
        KonohaClass *cGlobalObject = KLIB kNameSpace_DefineClass(kctx, ns, NULL, &defGlobalObject, trace);
        ((kNameSpaceVar *)ns)->globalObjectNULL_OnList =  KLIB Knull(kctx, cGlobalObject);
        return KLIB kNameSpace_SetConstData(kctx, ns, SYM_("global"), cGlobalObject->typeId, (uintptr_t)ns->globalObjectNULL_OnList, true/*isOverride*/, trace);
    }
    return true;
}
Beispiel #11
0
static kbool_t dynamic_PackupNameSpace(KonohaContext *kctx, kNameSpace *ns, int option, KTraceInfo *trace)
{
	static KDEFINE_CLASS defDynamic = {0};
	defDynamic.structname = "dynamic";
	defDynamic.cflag = kClass_Final|kClass_TypeVar;
	KonohaClass *cDynamic = KLIB kNameSpace_DefineClass(kctx, ns, NULL, &defDynamic, trace);
	int TY_Dynamic = cDynamic->typeId;
	KDEFINE_METHOD MethodData[] = {
		_Public|_Im, _F(Dynamic_), TY_Object, TY_Dynamic, MN_(""), 0,
		DEND,
	};
	KLIB kNameSpace_LoadMethodData(kctx, ns, MethodData, trace);
	return true;
}
Beispiel #12
0
static void stat_defineClassAndMethod(KonohaContext *kctx, kNameSpace *ns, KTraceInfo *trace)
{
	KDEFINE_CLASS defStat = {};
	defStat.structname = "FileStatus";
	defStat.typeId = KTypeAttr_NewId;
	defStat.cstruct_size = sizeof(struct kFileStatusVar);
	defStat.cflag = KClassFlag_Final;
	defStat.init  = kFileStatus_Init;
	defStat.free  = kFileStatus_Free;
	defStat.format     = kFileStatus_format;
	KClass *cStat = KLIB kNameSpace_DefineClass(kctx, ns, NULL, &defStat, trace);
	int KType_Stat = cStat->typeId;
	KDEFINE_METHOD MethodData[] = {
		_Public|_Static, _F(System_stat),  KType_Stat, KType_System, KMethodName_("stat"), 1, KType_String, KFieldName_("path"),
		_Public|_Static, _F(System_lstat), KType_Stat, KType_System, KMethodName_("lstat"), 1, KType_String, KFieldName_("path"),
		_Public|_Static, _F(System_fstat), KType_Stat, KType_System, KMethodName_("fstat"), 1, KType_Int, KFieldName_("fd"),
		_Public|_Const|_Im, _F(Stat_getdev), KType_Int, KType_Stat, KMethodName_("getdev"), 0,
		_Public|_Const|_Im, _F(Stat_getino), KType_Int, KType_Stat, KMethodName_("getino"), 0,
		_Public|_Const|_Im, _F(Stat_getmode), KType_Int, KType_Stat, KMethodName_("getmode"), 0,
		_Public|_Const|_Im, _F(Stat_getnlink), KType_Int, KType_Stat, KMethodName_("getnlink"), 0,
		_Public|_Const|_Im, _F(Stat_getuid), KType_Int, KType_Stat, KMethodName_("getuid"), 0,
		_Public|_Const|_Im, _F(Stat_getgid), KType_Int, KType_Stat, KMethodName_("getgid"), 0,
		_Public|_Const|_Im, _F(Stat_getsize), KType_Int, KType_Stat, KMethodName_("getsize"), 0,
		_Public|_Const|_Im, _F(Stat_getatime), KType_Int, KType_Stat, KMethodName_("getatime"), 0,
		_Public|_Const|_Im, _F(Stat_getmtime), KType_Int, KType_Stat, KMethodName_("getmtime"), 0,
		_Public|_Const|_Im, _F(Stat_getctime), KType_Int, KType_Stat, KMethodName_("getctime"), 0,
#ifdef HAVE_STRUKClass_STAT_ST_RDEV
		_Public|_Const|_Im, _F(Stat_getrdev), KType_Int, KType_Stat, KMethodName_("getrdev"), 0,
#endif /* HAVE_STRUKClass_STAT_ST_RDEV */
#ifdef HAVE_STRUKClass_STAT_ST_BLOCKS
		_Public|_Const|_Im, _F(Stat_getblocks), KType_Int, KType_Stat, KMethodName_("getblocks"), 0,
#endif /* HAVE_STRUKClass_STAT_ST_BLOCKS */
#ifdef HAVE_STRUKClass_STAT_ST_BLKSIZE
		_Public|_Const|_Im, _F(Stat_getblksize), KType_Int, KType_Stat, KMethodName_("getblksize"), 0,
#endif /* HAVE_STRUKClass_STAT_ST_BLKSIZE */
#ifdef HAVE_STRUKClass_STAT_ST_FLAGS
		_Public|_Const|_Im, _F(Stat_getflags), KType_Int, KType_Stat, KMethodName_("getflags"), 0,
#endif /* HAVE_STRUKClass_STAT_ST_FLAGS */
#ifdef HAVE_STRUKClass_STAT_ST_GEN
		_Public|_Const|_Im, _F(Stat_getgen), KType_Int, KType_Stat, KMethodName_("getgen"), 0,
#endif /* HAVE_STRUKClass_STAT_ST_GEN */
#ifdef HAVE_STRUKClass_STAT_ST_BIRTHTIME
		_Public|_Const|_Im, _F(Stat_getbirthtime), KType_Int, KType_Stat, KMethodName_("getbirthtime"), 0,
#endif /* HAVE_STRUKClass_STAT_ST_BIRTHTIME */

		DEND,
	};
	KLIB kNameSpace_LoadMethodData(kctx, ns, MethodData, trace);
}
Beispiel #13
0
static KonohaClass *loadcidClass(KonohaContext *kctx, kNameSpace *ns, KTraceInfo *trace)
{
	static KDEFINE_CLASS defcid = {0};
	defcid.structname = "cid";
	defcid.cflag = CFLAG_int;
	defcid.init = CT_(TY_int)->init;
	defcid.unbox = CT_(TY_int)->unbox;
	defcid.p = kcid_p;
	KonohaClass *ccid = KLIB kNameSpace_DefineClass(kctx, ns, NULL, &defcid, trace);
	KDEFINE_METHOD MethodData[] = {
		_Public|_Coercion|_Const, _F(Object_tocid), ccid->typeId, TY_Object, MN_to(ccid->typeId), 0,
		DEND,
	};
	KLIB kNameSpace_LoadMethodData(kctx, ns, MethodData, trace);
	return ccid;
}
Beispiel #14
0
static KonohaClass *defineSymbolClass(KonohaContext *kctx, kNameSpace *ns, KTraceInfo *trace)
{
	static KDEFINE_CLASS defSymbol = {0};
	defSymbol.structname = "Symbol";
	defSymbol.cflag = CFLAG_int;
	defSymbol.init = CT_(TY_int)->init;
	defSymbol.unbox = CT_(TY_int)->unbox;
	defSymbol.p = kSymbol_p;
	KonohaClass *cSymbol = KLIB kNameSpace_DefineClass(kctx, ns, NULL, &defSymbol, trace);
	KDEFINE_METHOD MethodData[] = {
		_Public|_Coercion|_Const, _F(String_toSymbol), cSymbol->typeId, TY_String, MN_to(cSymbol->typeId), 0,
		DEND,
	};
	KLIB kNameSpace_LoadMethodData(kctx, ns, MethodData, trace);
	return cSymbol;
}
Beispiel #15
0
static KonohaClassVar* kNameSpace_DefineClassName(KonohaContext *kctx, kNameSpace *ns, kshortflag_t cflag, kString *name, KTraceInfo *trace)
{
	KDEFINE_CLASS defNewClass = {0};
	defNewClass.cflag         = cflag | kClass_Nullable;
	defNewClass.typeId       = TY_newid;
	defNewClass.baseTypeId   = TY_Object;
	defNewClass.superTypeId  = TY_Object; //superClass->typeId;
	defNewClass.init = Object_InitToMakeDefaultValueAsNull; // dummy for first generation of DefaultValueAsNull

	KonohaClassVar *definedClass = (KonohaClassVar *)KLIB kNameSpace_DefineClass(kctx, ns, name, &defNewClass, trace);
	KDEFINE_CLASS_CONST ClassData[] = {
		{S_text(name), VirtualType_KonohaClass, definedClass},
		{NULL},
	};
	KLIB kNameSpace_LoadConstData(kctx, ns, KonohaConst_(ClassData), false/*isOverride*/, true);
	return definedClass;
}
Beispiel #16
0
static kbool_t file_PackupNameSpace(KonohaContext *kctx, kNameSpace *ns, int option, KTraceInfo *trace)
{
	KRequireKonohaCommonModule(trace);
	KRequirePackage("Type.Bytes", trace);
	if(KClass_File == NULL) {
		KDEFINE_CLASS defFile = {
			.structname = "File",
			.typeId = KTypeAttr_NewId,
			.cstruct_size = sizeof(kFile),
			.cflag = KClassFlag_Final,
			.init  = kFile_Init,
			.reftrace = kFile_Reftrace,
			.free   = kFile_Free,
			.format = kFile_format,
		};
		KClass_File = KLIB kNameSpace_DefineClass(kctx, ns, NULL, &defFile, trace);
	}
	file_defineMethod(kctx, ns, trace);
	file_defineConst(kctx, ns, trace);
	return true;
}
Beispiel #17
0
static void path_defineDIR(KonohaContext *kctx, kNameSpace *ns, KTraceInfo *trace)
{
	KDEFINE_CLASS defDIR = {};
	defDIR.structname = "DIR";
	defDIR.typeId = KTypeAttr_NewId;
	defDIR.cstruct_size = sizeof(struct kDirVar);
	defDIR.cflag = KClassFlag_Final;
	defDIR.init  = kDir_Init;
	defDIR.reftrace  = kDir_Reftrace;
	defDIR.free  = kDir_Free;
	defDIR.format     = kDir_format;
	KClass *cDIR = KLIB kNameSpace_DefineClass(kctx, ns, NULL, &defDIR, trace);
	int KType_DIR = cDIR->typeId;
	KDEFINE_METHOD MethodData[] = {
		_Public|_Static|_C, _F(System_opendir),   KType_DIR,    KType_System, KMethodName_("opendir"),  1, KType_String, KFieldName_("dirname"),
		_Public,            _F(DIR_close),        KType_void,   KType_DIR,    KMethodName_("close"), 0,
		_Public|_Iter,      _F(DIR_readFileName), KType_String, KType_DIR,    KMethodName_("readFileName"), 0,
		_Public|_Iter,      _F(DIR_readPath),     KType_String, KType_DIR,    KMethodName_("readPath"), 0,
		DEND,
	};
	KLIB kNameSpace_LoadMethodData(kctx, ns, MethodData, trace);
}
Beispiel #18
0
static kbool_t console_PackupNameSpace(KonohaContext *kctx, kNameSpace *ns, int option, KTraceInfo *trace)
{
	KDEFINE_CLASS defConsole = {0};
	SETSTRUCTNAME(defConsole, Console);
	defConsole.cflag = KClassFlag_Final | KClassFlag_Singleton;

	KClass *cConsole = KLIB kNameSpace_DefineClass(kctx, ns, NULL, &defConsole, trace);
	int KType_Console = cConsole->typeId;

	KDEFINE_METHOD MethodData[] = {
		_Public|_Static, _F(Console_notify), KType_void, KType_Console, KMethodName_("notify"), 1, KType_String, KFieldName_("message"),
		_Public|_Static, _F(Console_readLine), KType_String, KType_Console, KMethodName_("readLine"), 1, KType_String, KFieldName_("message"),
		_Public|_Static, _F(Console_inputUserApproval), KType_Boolean, KType_Console, KMethodName_("inputUserApproval"), 4,
		    KType_String, KFieldName_("message"), KType_String, KFieldName_("yes"), KType_String, KFieldName_("no"), KType_Boolean, KFieldName_("defval"),
		_Public|_Static, _F(Console_inputUserPassword), KType_String, KType_Console, KMethodName_("inputUserPassword"), 1, KType_String, KFieldName_("message"),
		_Public|_Static, _F(Console_inputUserPassword0), KType_String, KType_Console, KMethodName_("inputUserPassword"), 0,
		DEND,
	};
	KLIB kNameSpace_LoadMethodData(kctx, ns, MethodData, trace);

	return true;
}
Beispiel #19
0
static void path_defineDIR(KonohaContext *kctx, kNameSpace *ns, KTraceInfo *trace)
{
	KDEFINE_CLASS defDIR = {};
	defDIR.structname = "DIR";
	defDIR.typeId = TY_newid;
	defDIR.cstruct_size = sizeof(struct kDirVar);
	defDIR.cflag = kClass_Final;
	defDIR.init  = kDir_Init;
	defDIR.reftrace  = kDir_Reftrace;
	defDIR.free  = kDir_Free;
	defDIR.p     = kDir_p;
	KonohaClass *cDIR = KLIB kNameSpace_DefineClass(kctx, ns, NULL, &defDIR, trace);
	int TY_DIR = cDIR->typeId;
	KDEFINE_METHOD MethodData[] = {
		_Public|_Static|_C, _F(System_opendir),   TY_DIR,    TY_System, MN_("opendir"),  1, TY_String, FN_("dirname"),
		_Public,            _F(DIR_close),        TY_void,   TY_DIR,    MN_("close"), 0,
		_Public|_Iter,      _F(DIR_readFileName), TY_String, TY_DIR,    MN_("readFileName"), 0,
		_Public|_Iter,      _F(DIR_readPath),     TY_String, TY_DIR,    MN_("readPath"), 0,
		DEND,
	};
	KLIB kNameSpace_LoadMethodData(kctx, ns, MethodData, trace);
}
Beispiel #20
0
static kbool_t math_PackupNameSpace(KonohaContext *kctx, kNameSpace *ns, int option, KTraceInfo *trace)
{
	KRequirePackage("Type.Float", trace);
	static KDEFINE_CLASS MathDef = {0};
	MathDef.cflag = KClassFlag_Singleton|KClassFlag_Final;
	MathDef.structname = "Math"; /*structname*/
	MathDef.typeId = KTypeAttr_NewId; /*cid*/

	KClass *cMath = KLIB kNameSpace_DefineClass(kctx, ns, NULL, &MathDef, trace);
	int FN_x = KFieldName_("x");
	int FN_y = KFieldName_("y");
	KDEFINE_METHOD MethodData[] = {
			_Public|_Const|_Static, _F(Math_abs), KType_Int, KType_Math, KMethodName_("abs"), 1, KType_Int, FN_x,
			_Public|_Const|_Static, _F(Math_fabs), KType_float, KType_Math, KMethodName_("fabs"), 1, KType_float, FN_x,
			_Public|_Const|_Static, _F(Math_pow), KType_float, KType_Math, KMethodName_("pow"), 2, KType_float, FN_x, KType_float, FN_y,
			_Public|_Const|_Static, _F(Math_ldexp), KType_float, KType_Math, KMethodName_("ldexp"), 2, KType_float, FN_x, KType_Int, FN_y,
			_Public|_Const|_Static, _F(Math_modf), KType_float, KType_Math, KMethodName_("modf"), 2, KType_float, FN_x, KType_float, FN_y,
			_Public|_Const|_Static, _F(Math_frexp), KType_float, KType_Math, KMethodName_("frexp"), 2, KType_float, FN_x, KType_Int, FN_y,
			_Public|_Const|_Static, _F(Math_fmod), KType_float, KType_Math, KMethodName_("fmod"), 2, KType_float, FN_x, KType_float, FN_y,
			_Public|_Const|_Static, _F(Math_ceil), KType_float, KType_Math, KMethodName_("ceil"), 1, KType_float, FN_x,
#ifdef K_USING_WIN32_
			_Public, _F(Math_round), KType_float, KType_Math, KMethodName_("round"), 1, KType_float, FN_x,
			_Public, _F(Math_nearByInt), KType_float, KType_Math, KMethodName_("nearByInt"), 1, KType_float, FN_x,
#endif
			_Public|_Const|_Static, _F(Math_floor), KType_float, KType_Math, KMethodName_("floor"), 1, KType_float, FN_x,
			_Public|_Const|_Static, _F(Math_sqrt), KType_float, KType_Math, KMethodName_("sqrt"), 1, KType_float, FN_x,
			_Public|_Const|_Static, _F(Math_exp), KType_float, KType_Math, KMethodName_("exp"), 1, KType_float, FN_x,
			_Public|_Const|_Static, _F(Math_log10), KType_float, KType_Math, KMethodName_("log10"), 1, KType_float, FN_x,
			_Public|_Const|_Static, _F(Math_log), KType_float, KType_Math, KMethodName_("log"), 1, KType_float, FN_x,
			_Public|_Const|_Static, _F(Math_sin), KType_float, KType_Math, KMethodName_("sin"), 1, KType_float, FN_x,
			_Public|_Const|_Static, _F(Math_cos), KType_float, KType_Math, KMethodName_("cos"), 1, KType_float, FN_x,
			_Public|_Const|_Static, _F(Math_tan), KType_float, KType_Math, KMethodName_("tan"), 1, KType_float, FN_x,
			_Public|_Const|_Static, _F(Math_asin), KType_float, KType_Math, KMethodName_("asin"), 1, KType_float, FN_x,
			_Public|_Const|_Static, _F(Math_acos), KType_float, KType_Math, KMethodName_("acos"), 1, KType_float, FN_x,
			_Public|_Const|_Static, _F(Math_atan), KType_float, KType_Math, KMethodName_("atan"), 1, KType_float, FN_x,
			_Public|_Const|_Static, _F(Math_atan2), KType_float, KType_Math, KMethodName_("atan2"), 2, KType_float, FN_x, KType_float, FN_y,
			_Public|_Const|_Static, _F(Math_sinh), KType_float, KType_Math, KMethodName_("sinh"), 1, KType_float, FN_x,
			_Public|_Const|_Static, _F(Math_cosh), KType_float, KType_Math, KMethodName_("cosh"), 1, KType_float, FN_x,
			_Public|_Const|_Static, _F(Math_tanh), KType_float, KType_Math, KMethodName_("tanh"), 1, KType_float, FN_x,
#if defined(K_USING_WIN32_)
			_Public|_Const|_Static, _F(Math_asinh), KType_float, KType_Math, KMethodName_("asinh"), 1, KType_float, FN_x,
			_Public|_Const|_Static, _F(Math_acosh), KType_float, KType_Math, KMethodName_("acosh"), 1, KType_float, FN_x,
			_Public|_Const|_Static, _F(Math_atanh), KType_float, KType_Math, KMethodName_("atanh"), 1, KType_float, FN_x,
#endif
			_Public, _F(Math_random), KType_float, KType_Math, KMethodName_("random"), 0,
			DEND,
	};
	KLIB kNameSpace_LoadMethodData(kctx, ns, MethodData, trace);

	KDEFINE_FLOAT_CONST FloatData[] = {
			{MATH_(E)},
			{MATH_(LOG2E)},
			{MATH_(LOG10E)},
			{MATH_(LN2)},
			{MATH_(LN10)},
			{MATH_(PI)},
			{MATH_(SQRT2)},
			{}
	};
	KLIB kNameSpace_LoadConstData(kctx, ns, KConst_(FloatData), trace);
	return true;
}
Beispiel #21
0
		.free     = kThread_Free,
		.compareObject = kThread_compareTo,
	};
	KDEFINE_CLASS defMutex = {
		STRUCTNAME(Mutex),
		.cflag = kClass_Final,
		.init  = kMutex_Init,
		.free  = kMutex_Free,
	};
	KDEFINE_CLASS defCond = {
		STRUCTNAME(Cond),
		.cflag = kClass_Final,
		.init  = kCond_Init,
		.free  = kCond_Free,
	};
	KonohaClass *cThread = KLIB kNameSpace_DefineClass(kctx, ns, NULL, &defThread, trace);
	KonohaClass *cMutex  = KLIB kNameSpace_DefineClass(kctx, ns, NULL, &defMutex, trace);
	KonohaClass *cCond   = KLIB kNameSpace_DefineClass(kctx, ns, NULL, &defCond, trace);

	kparamtype_t P_Func[] = {{}};
	int TY_FUNC = (KLIB KonohaClass_Generics(kctx, CT_Func, TY_void, 0, P_Func))->typeId;

	int FN_func = FN_("func");
	int FN_x = FN_("x");
	KDEFINE_METHOD MethodData[] = {
		_Public|_Static, _F(Thread_create), TY_Thread, TY_Thread, MN_("create"), 1, TY_FUNC, FN_func,
		_Public, _F(Thread_join)   , TY_void, TY_Thread, MN_("join"), 0,
		_Public, _F(Thread_exit)   , TY_void, TY_Thread, MN_("exit"), 0,
		_Public, _F(Thread_cancel) , TY_void, TY_Thread, MN_("cancel"), 0,
		_Public, _F(Thread_detach) , TY_void, TY_Thread, MN_("detach"), 0,
		_Public|_Static, _F(Thread_self)   , TY_Thread , TY_Thread, MN_("self"), 0,
Beispiel #22
0
		STRUCTNAME(Connection),
		.cflag = KClassFlag_Final,
		.init = kConnection_Init,
		.free = kConnection_Free,
	};

	static KDEFINE_CLASS ResultSetDef = {
		STRUCTNAME(ResultSet),
		.cflag = KClassFlag_Final,
		.init = kResultSet_Init,
		.free = kResultSet_Free,
		.reftrace = kResultSet_Reftrace,
		.format = kResultSet_format,
	};

	KClass *cConnection = KLIB kNameSpace_DefineClass(kctx, ns, NULL, &ConnectionDef, trace);
	KClass *cResultSet = KLIB kNameSpace_DefineClass(kctx, ns, NULL, &ResultSetDef, trace);

	KDEFINE_METHOD MethodData[] = {
		/* Connection method */
		_Public, _F(Connection_new), KType_Connection, KType_Connection, KMethodName_("new"), 1, KType_String, KFieldName_("dbname"),
		_Public, _F(Connection_close), KType_void, KType_Connection, KMethodName_("close"), 0,
		_Public, _F(Connection_query), KType_ResultSet, KType_Connection, KMethodName_("query"), 1, KType_String, KFieldName_("query"),
#ifdef HAVE_MYSQL
		_Public, _F(Connection_getInsertId), KType_Int, KType_Connection, KMethodName_("getInsertId"), 0,
#endif

		/* ResultSet method */
		_Public, _F(ResultSet_getInt), KType_Int, KType_ResultSet, KMethodName_("getInt"), 1, KType_String, KFieldName_("query"),
		_Public, _F(ResultSet_getBoolean), KType_Boolean, KType_ResultSet, KMethodName_("getBoolean"), 1, KType_String, KFieldName_("query"),
		_Public, _F(ResultSet_getFloat), KType_float, KType_ResultSet, KMethodName_("getFloat"), 1, KType_String, KFieldName_("query"),
Beispiel #23
0
#define _Im kMethod_Immutable
#define _F(F)   (intptr_t)(F)

#define TY_SockAddr         cSockAddr->typeId

#define KDefineConstInt(T) #T, TY_int, T

static kbool_t socket_PackupNameSpace(KonohaContext *kctx, kNameSpace *ns, int option, KTraceInfo *trace)
{
	KDEFINE_CLASS defSockAddr = {
		STRUCTNAME(SockAddr),
		.cflag = kClass_Final,
		.init = SockAddr_Init,
		.free = SockAddr_Free,
	};
	KonohaClass *cSockAddr = KLIB kNameSpace_DefineClass(kctx, ns, NULL, &defSockAddr, trace);
	kparamtype_t pi = {TY_int, FN_("intValue")};
	KonohaClass *CT_IntArray = KLIB KonohaClass_Generics(kctx, CT_Array, TY_int, 1, &pi);
	ktype_t TY_intArray = CT_IntArray->typeId;

	KDEFINE_METHOD MethodData[] = {
		_Public|_Static|_Const|_Im, _F(System_accept), TY_int, TY_System, MN_("accept"), 2, TY_int, FN_("fd"), TY_SockAddr, FN_("sockaddr"),
		_Public|_Static|_Const|_Im, _F(System_bind), TY_int, TY_System, MN_("bind"), 4, TY_int, FN_("fd"), TY_String, FN_("srcIP"), TY_int, FN_("srcPort"), TY_int, FN_("family"),
		_Public|_Static|_Const|_Im, _F(System_close), TY_int, TY_System, MN_("close"), 1, TY_int, FN_("fd"),
		_Public|_Static|_Const|_Im, _F(System_connect), TY_int, TY_System, MN_("connect"), 4, TY_int, FN_("fd"), TY_String, FN_("dstIP"), TY_int, FN_("dstPort"), TY_int, FN_("family"),
		_Public|_Static|_Const|_Im, _F(System_listen), TY_int, TY_System, MN_("listen"), 2, TY_int, FN_("fd"), TY_int, FN_("backlog"),
//		_Public|_Static|_Const|_Im, _F(System_getsockname), TY_Map TY_System, MN_("getsockname"),1, TY_int, FN_("fd"),
		_Public|_Static|_Const|_Im, _F(System_getsockopt), TY_int, TY_System, MN_("getsockopt"), 2, TY_int, FN_("fd"), TY_int, FN_("opt"),
		_Public|_Static|_Const|_Im, _F(System_setsockopt), TY_int, TY_System, MN_("setsockopt"), 3, TY_int, FN_("fd"), TY_int, FN_("opt"), TY_int, FN_("value"),
//		_Public|_Static|_Const|_Im, _F(System_getpeername), TY_Map, TY_System, MN_("getpeername"), 1, TY_int, FN_("fd"),
		_Public|_Static, _F(System_Select), TY_int, TY_System, MN_("select"), 5, TY_intArray, FN_("readsocks"), TY_intArray, FN_("writesocks"), TY_intArray, FN_("exceptsocks"), TY_int, FN_("timeoutSec"), TY_int, FN_("timeoutUSec"),
Beispiel #24
0
{
	static KDEFINE_CLASS TaggerDef = {
		STRUCTNAME(Tagger),
		.cflag = KClassFlag_Final,
		.init = Tagger_Init,
		.free = Tagger_Free,
	};

	static KDEFINE_CLASS MecabNodeDef = {
		STRUCTNAME(MecabNode),
		.cflag = KClassFlag_Final,
		.init = MecabNode_Init,
		.free = MecabNode_Free,
	};

	KClass *cTagger = KLIB kNameSpace_DefineClass(kctx, ns, NULL, &TaggerDef, trace);
	KClass *cMecabNode = KLIB kNameSpace_DefineClass(kctx, ns, NULL, &MecabNodeDef, trace);

	KDEFINE_METHOD MethodData[] = {
		_Public|_Const, _F(Tagger_new),         KType_Tagger,  KType_Tagger, KMethodName_("new"),   0,
		_Public|_Const, _F(Tagger_Parse),       KType_String,  KType_Tagger, KMethodName_("parse"), 1, KType_String, KFieldName_("input"),
		_Public|_Const, _F(Tagger_NBestParse),  KType_String,  KType_Tagger, KMethodName_("NBestParse"), 2, KType_Int, KFieldName_("n"), KType_String, KFieldName_("input"),
		_Public|_Const, _F(Tagger_NBestInit),   KType_String,  KType_Tagger, KMethodName_("NBestInit"), 1, KType_String, KFieldName_("input"),
		_Public|_Const, _F(Tagger_NBestNext),   KType_String,  KType_Tagger, KMethodName_("NBestNext"), 0,
		_Public|_Const, _F(Tagger_ParseToNode), KType_MecabNode,  KType_Tagger, KMethodName_("parseToNode"), 1, KType_String, KFieldName_("input"),
		_Public|_Const, _F(Tagger_destroy),     KType_void,    KType_Tagger, KMethodName_("destroy"), 0,

		_Public|_Const, _F(MecabNode_next),        KType_MecabNode,  KType_MecabNode, KMethodName_("next"), 0,
		_Public|_Const, _F(MecabNode_prev),        KType_MecabNode,  KType_MecabNode, KMethodName_("prev"), 0,
		_Public|_Const, _F(MecabNode_enext),       KType_MecabNode,  KType_MecabNode, KMethodName_("enext"), 0,
		_Public|_Const, _F(MecabNode_bnext),       KType_MecabNode,  KType_MecabNode, KMethodName_("bnext"), 0,
Beispiel #25
0
static kbool_t curl_PackupNameSpace(KonohaContext *kctx, kNameSpace *ns, int option, KTraceInfo *trace)
{
	KRequireKonohaCommonModule(trace);
	KRequirePackage("Type.File", trace);

	KDEFINE_CLASS defCurl = {
		STRUCTNAME(Curl),
		.cflag = KClassFlag_Final,
		.init = kCurl_Init,
		.reftrace = kCurl_Reftrace,
		.free = kCurl_Free,
	};
	KClass *cCurl = KLIB kNameSpace_DefineClass(kctx, ns, NULL, &defCurl, trace);

	KDEFINE_METHOD MethodData[] = {
		_Public, _F(Curl_new), KType_Curl, KType_Curl, KMethodName_("new"), 0,
		_Public, _F(Curl_SetOptBoolean), KType_void, KType_Curl, KMethodName_("setOpt"), 2, KType_Int, KFieldName_("option"), KType_Boolean, KFieldName_("data"),
		_Public, _F(Curl_SetOptInt),     KType_void, KType_Curl, KMethodName_("setOpt"), 2, KType_Int, KFieldName_("option"), KType_Int,     KFieldName_("data"),
		_Public, _F(Curl_SetOptString),  KType_void, KType_Curl, KMethodName_("setOpt"), 2, KType_Int, KFieldName_("option"), KType_String,  KFieldName_("data"),
		_Public, _F(Curl_SetOptFile),    KType_void, KType_Curl, KMethodName_("setOpt"), 2, KType_Int, KFieldName_("option"), KType_File,    KFieldName_("data"),
		_Public, _F(Curl_appendHeader), KType_void, KType_Curl, KMethodName_("appendHeader"), 1, KType_String, KFieldName_("header"),
		_Public, _F(Curl_perform), KType_Boolean, KType_Curl, KMethodName_("perform"), 0,
		_Public, _F(Curl_receiveString), KType_String, KType_Curl, KMethodName_("receiveString"), 0,
		_Public|_Im, _F(Curl_getInfo), KType_Object/*FIXME KType_Dynamic*/, KType_Curl, KMethodName_("getInfo"), 1, KType_Int, KFieldName_("type"),
		DEND,
	};
	KLIB kNameSpace_LoadMethodData(kctx, ns, MethodData, trace);

	KDEFINE_INT_CONST IntData[] = {
		{KDefineConstInt(CURLOPT_AUTOREFERER)},
		{KDefineConstInt(CURLOPT_COOKIESESSION)},
		{KDefineConstInt(CURLOPT_CRLF)},
		{KDefineConstInt(CURLOPT_DNS_USE_GLOBAL_CACHE)},
		{KDefineConstInt(CURLOPT_FAILONERROR)},
		{KDefineConstInt(CURLOPT_FILETIME)},
		{KDefineConstInt(CURLOPT_FOLLOWLOCATION)},
		{KDefineConstInt(CURLOPT_FORBID_REUSE)},
		{KDefineConstInt(CURLOPT_FRESH_CONNECT)},
		{KDefineConstInt(CURLOPT_FTP_USE_EPRT)},
		{KDefineConstInt(CURLOPT_FTP_USE_EPSV)},
		{KDefineConstInt(CURLOPT_FTPAPPEND)},
		{KDefineConstInt(CURLOPT_FTPLISTONLY)},
		{KDefineConstInt(CURLOPT_HEADER)},
		{KDefineConstInt(CURLOPT_HTTPGET)},
		{KDefineConstInt(CURLOPT_HTTPPROXYTUNNEL)},
		{KDefineConstInt(CURLOPT_NETRC)},
		{KDefineConstInt(CURLOPT_NOBODY)},
		{KDefineConstInt(CURLOPT_NOPROGRESS)},
		{KDefineConstInt(CURLOPT_NOSIGNAL)},
		{KDefineConstInt(CURLOPT_POST)},
		{KDefineConstInt(CURLOPT_PUT)},
		{KDefineConstInt(CURLOPT_SSL_VERIFYPEER)},
		{KDefineConstInt(CURLOPT_TRANSFERTEXT)},
		{KDefineConstInt(CURLOPT_UNRESTRICTED_AUTH)},
		{KDefineConstInt(CURLOPT_UPLOAD)},
		{KDefineConstInt(CURLOPT_VERBOSE)},
		{KDefineConstInt(CURLOPT_BUFFERSIZE)},
		{KDefineConstInt(CURLOPT_CLOSEPOLICY)},
		{KDefineConstInt(CURLOPT_CONNECTTIMEOUT)},
		{KDefineConstInt(CURLOPT_DNS_CACHE_TIMEOUT)},
		{KDefineConstInt(CURLOPT_FTPSSLAUTH)},
		{KDefineConstInt(CURLOPT_HTTP_VERSION)},
		{KDefineConstInt(CURLOPT_HTTPAUTH)},
		{KDefineConstInt(CURLAUTH_ANY)},
		{KDefineConstInt(CURLAUTH_ANYSAFE)},
		{KDefineConstInt(CURLOPT_INFILESIZE)},
		{KDefineConstInt(CURLOPT_LOW_SPEED_LIMIT)},
		{KDefineConstInt(CURLOPT_LOW_SPEED_TIME)},
		{KDefineConstInt(CURLOPT_MAXCONNECTS)},
		{KDefineConstInt(CURLOPT_MAXREDIRS)},
		{KDefineConstInt(CURLOPT_PORT)},
		{KDefineConstInt(CURLOPT_PROXYAUTH)},
		{KDefineConstInt(CURLOPT_PROXYPORT)},
		{KDefineConstInt(CURLOPT_PROXYTYPE)},
		{KDefineConstInt(CURLOPT_RESUME_FROM)},
		{KDefineConstInt(CURLOPT_SSL_VERIFYHOST)},
		{KDefineConstInt(CURLOPT_SSLVERSION)},
		{KDefineConstInt(CURLOPT_TIMECONDITION)},
		{KDefineConstInt(CURLOPT_TIMEOUT)},
		{KDefineConstInt(CURLOPT_TIMEVALUE)},
		{KDefineConstInt(CURLOPT_CAINFO)},
		{KDefineConstInt(CURLOPT_CAPATH)},
		{KDefineConstInt(CURLOPT_COOKIE)},
		{KDefineConstInt(CURLOPT_COOKIEFILE)},
		{KDefineConstInt(CURLOPT_COOKIEJAR)},
		{KDefineConstInt(CURLOPT_CUSTOMREQUEST)},
		{KDefineConstInt(CURLOPT_ENCODING)},
		{KDefineConstInt(CURLOPT_FTPPORT)},
		{KDefineConstInt(CURLOPT_INTERFACE)},
		{KDefineConstInt(CURLOPT_KRB4LEVEL)},
		{KDefineConstInt(CURLOPT_POSTFIELDS)},
		{KDefineConstInt(CURLOPT_PROXY)},
		{KDefineConstInt(CURLOPT_PROXYUSERPWD)},
		{KDefineConstInt(CURLOPT_RANDOM_FILE)},
		{KDefineConstInt(CURLOPT_RANGE)},
		{KDefineConstInt(CURLOPT_REFERER)},
		{KDefineConstInt(CURLOPT_SSL_CIPHER_LIST)},
		{KDefineConstInt(CURLOPT_SSLCERT)},
		{KDefineConstInt(CURLOPT_SSLCERTTYPE)},
		{KDefineConstInt(CURLOPT_SSLENGINE)},
		{KDefineConstInt(CURLOPT_SSLENGINE_DEFAULT)},
		{KDefineConstInt(CURLOPT_SSLKEY)},
		{KDefineConstInt(CURLOPT_SSLKEYTYPE)},
		{KDefineConstInt(CURLOPT_URL)},
		{KDefineConstInt(CURLOPT_USERAGENT)},
		{KDefineConstInt(CURLOPT_USERPWD)},
		{KDefineConstInt(CURLOPT_FILE)},
		{KDefineConstInt(CURLOPT_WRITEDATA)},
		{KDefineConstInt(CURLOPT_READDATA)},
		{KDefineConstInt(CURLOPT_STDERR)},
		{KDefineConstInt(CURLOPT_WRITEHEADER)},
		{KDefineConstInt(CURLINFO_HEADER_SIZE)},
		{KDefineConstInt(CURLINFO_REQUEST_SIZE)},
		{KDefineConstInt(CURLINFO_REDIRECT_TIME)},
		{KDefineConstInt(CURLINFO_TOTAL_TIME)},
		{KDefineConstInt(CURLINFO_NAMELOOKUP_TIME)},
		{KDefineConstInt(CURLINFO_CONNECT_TIME)},
		{KDefineConstInt(CURLINFO_PRETRANSFER_TIME)},
		{KDefineConstInt(CURLINFO_STARTTRANSFER_TIME)},
		{KDefineConstInt(CURLINFO_SIZE_UPLOAD)},
		{KDefineConstInt(CURLINFO_SIZE_DOWNLOAD)},
		{KDefineConstInt(CURLINFO_SPEED_DOWNLOAD)},
		{KDefineConstInt(CURLINFO_SPEED_UPLOAD)},
		{KDefineConstInt(CURLINFO_EFFECTIVE_URL)},
		{KDefineConstInt(CURLINFO_CONTENT_TYPE)},
		{} // end of const data
	};
	KLIB kNameSpace_LoadConstData(kctx, ns, KConst_(IntData), trace);
	return true;
}
Beispiel #26
0
static kbool_t Libevent_PackupNameSpace(KonohaContext *kctx, kNameSpace *ns, int option, KTraceInfo *trace)
{
	/* Class Definition */
	/* If you want to create Generic class like Array<T>, see konoha.map package */
	// cevent_base
	KDEFINE_CLASS defcevent_base = {0};
	SETSTRUCTNAME(defcevent_base, cevent_base);
	defcevent_base.cflag     = KClassFlag_Final;	//must be final in C
	defcevent_base.init      = cevent_base_Init;
	defcevent_base.free      = cevent_base_Free;
	KClass *cevent_baseClass = KLIB kNameSpace_DefineClass(kctx, ns, NULL, &defcevent_base, trace);

	// cevent
	KDEFINE_CLASS defcevent = {0};
	SETSTRUCTNAME(defcevent, cevent);
	defcevent.cflag     = KClassFlag_Final;
	defcevent.init      = cevent_Init;
//	defcevent.reftrace  = cevent_Reftrace;
	defcevent.free      = cevent_Free;
	KClass *ceventClass = KLIB kNameSpace_DefineClass(kctx, ns, NULL, &defcevent, trace);

	// cbufferevent
	KDEFINE_CLASS defcbufferevent = {0};
	SETSTRUCTNAME(defcbufferevent, cbufferevent);
	defcbufferevent.cflag     = KClassFlag_Final;
	defcbufferevent.init      = cbufferevent_Init;
//	defcbufferevent.reftrace  = cbufferevent_Reftrace;
	defcbufferevent.free      = cbufferevent_Free;
	KClass *cbuffereventClass = KLIB kNameSpace_DefineClass(kctx, ns, NULL, &defcbufferevent, trace);

	// eventCBArg
	KDEFINE_CLASS defeventCBArg = {0};
	SETSTRUCTNAME(defeventCBArg, eventCBArg);
	defeventCBArg.cflag     = KClassFlag_Final;
	defeventCBArg.init      = eventCBArg_Init;
	defeventCBArg.reftrace  = eventCBArg_Reftrace;
	defeventCBArg.free      = eventCBArg_Free;
	KClass *eventCBArgClass = KLIB kNameSpace_DefineClass(kctx, ns, NULL, &defeventCBArg, trace);

	// buffereventCBArg
	KDEFINE_CLASS defbuffereventCBArg = {0};
	SETSTRUCTNAME(defbuffereventCBArg, buffereventCBArg);
	defbuffereventCBArg.cflag     = KClassFlag_Final;
	defbuffereventCBArg.init      = buffereventCBArg_Init;
	defbuffereventCBArg.reftrace  = buffereventCBArg_Reftrace;
	defbuffereventCBArg.free      = buffereventCBArg_Free;
	KClass *buffereventCBArgClass = KLIB kNameSpace_DefineClass(kctx, ns, NULL, &defbuffereventCBArg, trace);

	// ctimeval
	KDEFINE_CLASS defctimeval = {0};
	SETSTRUCTNAME(defctimeval, ctimeval);
	defctimeval.cflag     = KClassFlag_Final;
	defctimeval.init      = ctimeval_Init;
	KClass *ctimevalClass = KLIB kNameSpace_DefineClass(kctx, ns, NULL, &defctimeval, trace);

	// Sockaddr_in
	KDEFINE_CLASS defSockaddr_in = {0};
	SETSTRUCTNAME(defSockaddr_in, Sockaddr_in);
	defSockaddr_in.cflag     = KClassFlag_Final;
	defSockaddr_in.init      = Sockaddr_in_Init;
	KClass *Sockaddr_inClass = KLIB kNameSpace_DefineClass(kctx, ns, NULL, &defSockaddr_in, trace);


	/* You can define methods with the following procedures. */
	int KType_cevent_base = cevent_baseClass->typeId;
	int KType_cevent = ceventClass->typeId;
	int KType_cbufferevent = cbuffereventClass->typeId;
	int KType_eventCBArg = eventCBArgClass->typeId;
	int KType_buffereventCBArg = buffereventCBArgClass->typeId;
	int KType_ctimeval = ctimevalClass->typeId;
	int KType_Sockaddr_in = Sockaddr_inClass->typeId;

	/* define Generics parameter for callback method */
	//eventCB_p
	kparamtype_t eventCB_p[] = {{KType_Int, 0}, {KType_Int, 0}, {KType_Object, 0}};
	KClass *ceventCBfunc = KLIB KClass_Generics(kctx, KClass_Func, KType_void, 3, eventCB_p);
	int KType_ceventCBfunc = ceventCBfunc->typeId;
	//bev_dataCB_p
	kparamtype_t bev_dataCB_p[] = {{KType_cbufferevent, 0}, {KType_Object, 0}};
	KClass *Cbev_dataCBfunc = KLIB KClass_Generics(kctx, KClass_Func, KType_void, 2, bev_dataCB_p);
	int KType_Cbev_dataCBfunc = Cbev_dataCBfunc->typeId;
	//bev_eventCB_p
	kparamtype_t bev_eventCB_p[] = {{KType_cbufferevent, 0}, {KType_Int, 0}, {KType_Object, 0}};
	KClass *Cbev_eventCBfunc = KLIB KClass_Generics(kctx, KClass_Func, KType_void, 3, bev_eventCB_p);
	int KType_Cbev_eventCBfunc = Cbev_eventCBfunc->typeId;

	KDEFINE_METHOD MethodData[] = {
		// System class
		_Public|_Static, _F(System_evutil_make_socket_nonblocking), KType_Int, KType_System, KMethodName_("evutil_make_socket_nonblocking"), 1, KType_Int, KFieldName_("fd"),

		// cevent_base
		_Public, _F(cevent_base_new), KType_cevent_base, KType_cevent_base, KMethodName_("new"), 0,
		_Public, _F(cevent_base_event_dispatch), KType_Int, KType_cevent_base, KMethodName_("event_dispatch"), 0,

		// cevent
		_Public, _F(cevent_new), KType_cevent, KType_cevent, KMethodName_("new"), 4, KType_cevent_base, KFieldName_("cevent_base"), KType_Int, KFieldName_("evd"), KType_Int, KFieldName_("event"), KType_eventCBArg, KFieldName_("CBarg"),
		_Public, _F(cevent_event_add), KType_Int, KType_cevent, KMethodName_("event_add"), 1, KType_ctimeval, KFieldName_("timeval"),
		_Public, _F(cevent_event_del), KType_Int, KType_cevent, KMethodName_("event_del"), 0,
		_Public, _F(cevent_getID), KType_Int, KType_cevent, KMethodName_("getID"), 0, 
		_Public, _F(cevent_getEvents), KType_Int, KType_cevent, KMethodName_("getEvents"), 0, 

		// cbufferevent
		_Public, _F(cbufferevent_new), KType_cbufferevent, KType_cbufferevent, KMethodName_("new"), 3, KType_cevent_base, KFieldName_("cevent_base"), KType_Int, KFieldName_("evd"), KType_Int, KFieldName_("options"),
		_Public, _F(cbufferevent_setcb), KType_void, KType_cbufferevent, KMethodName_("bufferevent_setcb"), 1, KType_buffereventCBArg, KFieldName_("buffereventCBArg"),
		_Public, _F(cbufferevent_socket_connect), KType_Int, KType_cbufferevent, KMethodName_("bufferevent_socket_connect"), 1, KType_Sockaddr_in, KFieldName_("sockaddr"),
		_Public, _F(cbufferevent_enable), KType_Int, KType_cbufferevent, KMethodName_("bufferevent_enable"), 1, KType_Int, KFieldName_("event"),
		_Public, _F(cbufferevent_write), KType_Int, KType_cbufferevent, KMethodName_("bufferevent_write"), 1, KType_Bytes, KFieldName_("writebuffer"),
		_Public, _F(cbufferevent_read), KType_Int, KType_cbufferevent, KMethodName_("bufferevent_read"), 1, KType_Bytes, KFieldName_("readbuffer"),

		// eventCBArg
		_Public, _F(eventCBArg_new), KType_eventCBArg, KType_eventCBArg, KMethodName_("new"), 2, KType_ceventCBfunc, KFieldName_("konoha_CB"), KType_Object, KFieldName_("CBarg"),

		// buffereventCBArg
		_Public, _F(buffereventCBArg_new), KType_buffereventCBArg, KType_buffereventCBArg, KMethodName_("new"), 4, KType_Cbev_dataCBfunc, KFieldName_("readCB"), KType_Cbev_dataCBfunc, KFieldName_("writeCB"), KType_Cbev_eventCBfunc, KFieldName_("eventCB"), KType_Object, KFieldName_("CBarg"),

		// ctimeval
		_Public, _F(ctimeval_new), KType_ctimeval, KType_ctimeval, KMethodName_("new"), 2, KType_Int, KFieldName_("tv_sec"), KType_Int, KFieldName_("tv_usec"),

		// Sockaddr_in
		_Public, _F(Sockaddr_in_new), KType_Sockaddr_in, KType_Sockaddr_in, KMethodName_("new"), 3, KType_Int, KFieldName_("family"), KType_Int, KFieldName_("addr"), KType_Int, KFieldName_("port"),

		DEND, /* <= sentinel */
	};
	KLIB kNameSpace_LoadMethodData(kctx, ns, MethodData, trace);


	KDEFINE_INT_CONST IntData[] = {
		// === for event_new() ===
		{KDefineConstInt(EV_TIMEOUT)},
		{KDefineConstInt(EV_READ)},
		{KDefineConstInt(EV_WRITE)},
		{KDefineConstInt(EV_SIGNAL)},
		{KDefineConstInt(EV_PERSIST)},
		{KDefineConstInt(EV_ET)},

		// === for bufferevent ===
		// bufferevent.h
		{KDefineConstInt(BEV_EVENT_READING)},
		{KDefineConstInt(BEV_EVENT_WRITING)},
		{KDefineConstInt(BEV_EVENT_EOF)},
		{KDefineConstInt(BEV_EVENT_ERROR)},
		{KDefineConstInt(BEV_EVENT_TIMEOUT)},
		{KDefineConstInt(BEV_EVENT_CONNECTED)},

		// bufferevent.h: enum bufferevent_options
		{KDefineConstInt(BEV_OPT_CLOSE_ON_FREE)},
		{KDefineConstInt(BEV_OPT_THREADSAFE)},
		{KDefineConstInt(BEV_OPT_DEFER_CALLBACKS)},
		{KDefineConstInt(BEV_OPT_UNLOCK_CALLBACKS)},

		{KDefineConstInt(AF_INET)},// TODO should be implement in posix.socket package

		{} /* <= sentinel */
	};

	KLIB kNameSpace_LoadConstData(kctx, ns, KConst_(IntData), trace);

	return true;
}
Beispiel #27
0
static kbool_t date_PackupNameSpace(KonohaContext *kctx, kNameSpace *ns, int option, KTraceInfo *trace)
{
	KDEFINE_CLASS defDate = {0};
	SETSTRUCTNAME(defDate, Date);
	defDate.cflag = KClassFlag_Final;

	KClass *cDate = KLIB kNameSpace_DefineClass(kctx, ns, NULL, &defDate, trace);

	KDEFINE_METHOD MethodData[] = {
		_Public, _F(Date_new0), KType_Date, KType_Date, KMethodName_("new"), 0,
		_Public, _F(Date_new1), KType_Date, KType_Date, KMethodName_("new"), 1, KType_Int, KFieldName_("milliseconds"),
//		_Public, _F(Date_new2), KType_Date, KType_Date, KMethodName_("new"), 1, KType_String, KFieldName_("dateString"),
		_Public, _F(Date_new3), KType_Date, KType_Date, KMethodName_("new"), 7, KType_Int, KFieldName_("year"), KType_Int, KFieldName_("month"), KType_Int, KFieldName_("day"), KType_Int, KFieldName_("hour"), KType_Int, KFieldName_("minutes"), KType_Int, KFieldName_("seconds"), KType_Int, KFieldName_("milliseconds"),
		_Public|_Im, _F(Date_getDate), KType_Int, KType_Date, KMethodName_("getDate"), 0,
		_Public|_Im, _F(Date_getDay), KType_Int, KType_Date, KMethodName_("getDay"), 0,
		_Public|_Im, _F(Date_getFullYear), KType_Int, KType_Date, KMethodName_("getFullYear"), 0,
		_Public|_Im, _F(Date_getHours), KType_Int, KType_Date, KMethodName_("getHours"), 0,
		_Public|_Im, _F(Date_getMilliseconds), KType_Int, KType_Date, KMethodName_("getMilliseconds"), 0,
		_Public|_Im, _F(Date_getMinutes), KType_Int, KType_Date, KMethodName_("getMinutes"), 0,
		_Public|_Im, _F(Date_getMonth), KType_Int, KType_Date, KMethodName_("getMonth"), 0,
		_Public|_Im, _F(Date_getSeconds), KType_Int, KType_Date, KMethodName_("getSeconds"), 0,
		_Public|_Im, _F(Date_getTime), KType_Int, KType_Date, KMethodName_("getTime"), 0,
		_Public|_Im, _F(Date_getTimezoneOffset), KType_Int, KType_Date, KMethodName_("getTimezoneOffset"), 0,
		_Public|_Im, _F(Date_getUTCDate), KType_Int, KType_Date, KMethodName_("getUTCDate"), 0,
		_Public|_Im, _F(Date_getUTCDay), KType_Int, KType_Date, KMethodName_("getUTCDay"), 0,
		_Public|_Im, _F(Date_getUTCFullYear), KType_Int, KType_Date, KMethodName_("getUTCFullYear"), 0,
		_Public|_Im, _F(Date_getUTCHours), KType_Int, KType_Date, KMethodName_("getUTCHours"), 0,
		_Public|_Im, _F(Date_getUTCMilliseconds), KType_Int, KType_Date, KMethodName_("getUTCMilliseconds"), 0,
		_Public|_Im, _F(Date_getUTCMinutes), KType_Int, KType_Date, KMethodName_("getUTCMinutes"), 0,
		_Public|_Im, _F(Date_getUTCMonth), KType_Int, KType_Date, KMethodName_("getUTCMonth"), 0,
		_Public|_Im, _F(Date_getUTCSeconds), KType_Int, KType_Date, KMethodName_("getUTCSeconds"), 0,
		_Public|_Im, _F(Date_getYear), KType_Int, KType_Date, KMethodName_("getYear"), 0,
//		_Public|_Static, _F(Date_Parse), KType_Int, KType_Date, KMethodName_("parse"), 1, KType_String, KFieldName_("dateString"),
		_Public, _F(Date_SetDate), KType_Int, KType_Date, KMethodName_("setDate"), 1, KType_Int, KFieldName_("date"),
		_Public, _F(Date_SetFullYear), KType_Int, KType_Date, KMethodName_("setFullYear"), 1, KType_Int, KFieldName_("year"),
		_Public, _F(Date_SetHours), KType_Int, KType_Date, KMethodName_("setHours"), 1, KType_Int, KFieldName_("hours"),
		_Public, _F(Date_SetMilliseconds), KType_Int, KType_Date, KMethodName_("setMilliseconds"), 1, KType_Int, KFieldName_("milliseconds"),
		_Public, _F(Date_SetMinutes), KType_Int, KType_Date, KMethodName_("setMinutes"), 1, KType_Int, KFieldName_("minutes"),
		_Public, _F(Date_SetMonth), KType_Int, KType_Date, KMethodName_("setMonth"), 1, KType_Int, KFieldName_("month"),
		_Public, _F(Date_SetSeconds), KType_Int, KType_Date, KMethodName_("setSeconds"), 1, KType_Int, KFieldName_("seconds"),
		_Public, _F(Date_SetTime), KType_Int, KType_Date, KMethodName_("setTime"), 1, KType_Int, KFieldName_("milliseconds"),
		_Public, _F(Date_SetUTCDate), KType_Int, KType_Date, KMethodName_("setUTCDate"), 1, KType_Int, KFieldName_("date"),
		_Public, _F(Date_SetUTCFullYear), KType_Int, KType_Date, KMethodName_("setUTCFullYear"), 1, KType_Int, KFieldName_("year"),
		_Public, _F(Date_SetUTCHours), KType_Int, KType_Date, KMethodName_("setUTCHours"), 1, KType_Int, KFieldName_("hours"),
		_Public, _F(Date_SetUTCMilliseconds), KType_Int, KType_Date, KMethodName_("setUTCMilliseconds"), 1, KType_Int, KFieldName_("milliseconds"),
		_Public, _F(Date_SetUTCMinutes), KType_Int, KType_Date, KMethodName_("setUTCMinutes"), 1, KType_Int, KFieldName_("minutes"),
		_Public, _F(Date_SetUTCMonth), KType_Int, KType_Date, KMethodName_("setUTCMonth"), 1, KType_Int, KFieldName_("month"),
		_Public, _F(Date_SetUTCSeconds), KType_Int, KType_Date, KMethodName_("setUTCSeconds"), 1, KType_Int, KFieldName_("seconds"),
		_Public, _F(Date_SetYear), KType_Int, KType_Date, KMethodName_("setYear"), 1, KType_Int, KFieldName_("year"),
		_Public, _F(Date_toDateString), KType_String, KType_Date, KMethodName_("toDateString"), 0,
		_Public, _F(Date_toGMTString), KType_String, KType_Date, KMethodName_("toGMTString"), 0,
		_Public, _F(Date_toISOString), KType_String, KType_Date, KMethodName_("toISOString"), 0,
//		_Public, _F(Date_toJSON), KType_Json, KType_Date, KMethodName_("toJSON"), 0,
		_Public, _F(Date_toLocaleDateString), KType_String, KType_Date, KMethodName_("toLocaleDateString"), 0,
		_Public, _F(Date_toLocaleTimeString), KType_String, KType_Date, KMethodName_("toLocaleTimeString"), 0,
		_Public, _F(Date_toLocaleString), KType_String, KType_Date, KMethodName_("toLocaleString"), 0,
		_Public, _F(Date_toLocaleString), KType_String, KType_Date, KMethodName_("toString"), 0,
		_Public, _F(Date_toLocaleTimeString), KType_String, KType_Date, KMethodName_("toTimeString"), 0,
		_Public, _F(Date_toGMTString), KType_String, KType_Date, KMethodName_("toUTCString"), 0,
		DEND,
	};
	KLIB kNameSpace_LoadMethodData(kctx, ns, MethodData, trace);

	return true;
}
Beispiel #28
0
static kbool_t python_PackupNameSpace(KonohaContext *kctx, kNameSpace *ns, int option, KTraceInfo *trace)
{
	python_Init_count++;
	if(python_Init_count == 1) {
		Py_Initialize();
	}

	static KDEFINE_CLASS PythonDef = {
			STRUCTNAME(PyObject),
			.cflag = 0,
			.init = kPyObject_Init,
			.free = kPyObject_Free,
			.p    = kPyObject_p,
	};

	KClass *cPython = KLIB kNameSpace_DefineClass(kctx, ns, NULL, &PythonDef, trace);
	int KType_PyObject = cPython->typeId;
	KDEFINE_METHOD MethodData[] = {
		_Public|_Const|_Im|_Coercion, _F(PyObject_toBoolean), KType_Boolean, KType_PyObject, KMethodName_To(KType_Boolean), 0,
		_Public|_Const|_Im|_Coercion, _F(Boolean_toPyObject), KType_PyObject, KType_Boolean, KMethodName_To(KType_PyObject), 0,
		_Public|_Const|_Im|_Coercion, _F(PyObject_toInt), KType_Int, KType_PyObject, KMethodName_To(KType_Int), 0,
		_Public|_Const|_Im|_Coercion, _F(Int_toPyObject), KType_PyObject, KType_Int, KMethodName_To(KType_PyObject), 0,
		_Public|_Const|_Im|_Coercion, _F(PyObject_toString), KType_String, KType_PyObject, KMethodName_To(KType_String), 0,
		_Public|_Const|_Im|_Coercion, _F(String_toPyObject), KType_PyObject, KType_String, KMethodName_To(KType_PyObject), 0,
		//_Public,                      _F(Array_Add), KType_void, KType_Array, KMethodName_("add"), 1, KType_0, KFieldName_("value"),
		// [TODO] add following konoha class.
		//_Public|_Const|_Im|_Coercion, _F(PyObject_toList), KType_Array, KType_PyObject, KMethodName_To(KType_Array), 0,
		//_Public|_Const|_Im|_Coercion, _F(Array_toPyObject), KType_PyObject, KType_Array, KMethodName_To(KType_PyObject), 0,
		//_Public|_Const|_Im|_Coercion, _F(PyObject_toComplex), KType_Complex, KType_PyObject, KMethodName_To(KType_Complex), 0,
		//_Public|_Const|_Im|_Coercion, _F(Complex_toPyObject), KType_PyObject, KType_Complex, KMethodName_To(KType_PyObject), 0,
		//_Public|_Const|_Im|_Coercion, _F(PyObject_toBuffer), KType_Buffer, KType_PyObject, KMethodName_To(KType_Buffer), 0,
		//_Public|_Const|_Im|_Coercion, _F(Buffer_toPyObject), KType_PyObject, KType_Buffer, KMethodName_To(KType_PyObject), 0,
		//_Public|_Const|_Im|_Coercion, _F(PyObject_toTuple), KType_Tuple, KType_PyObject, KMethodName_To(KType_Tuple), 0,
		//_Public|_Const|_Im|_Coercion, _F(Tuple_toPyObject), KType_PyObject, KType_Tuple, KMethodName_To(KType_PyObject), 0,
		//_Public|_Const|_Im|_Coercion, _F(PyObject_toDict), KType_Dict, KType_PyObject, KMethodName_To(KType_Dict), 0,
		//_Public|_Const|_Im|_Coercion, _F(Dict_toPyObject), KType_PyObject, KType_Dict, KMethodName_To(KType_PyObject), 0,
		//_Public|_Const|_Im|_Coercion, _F(PyObject_toClass), KType_Class, KType_PyObject, KMethodName_To(KType_Class), 0,
		//_Public|_Const|_Im|_Coercion, _F(Class_toPyObject), KType_PyObject, KType_Class, KMethodName_To(KType_PyObject), 0,
		//_Public|_Const|_Im|_Coercion, _F(PyObject_asFunction), KType_Function, KType_PyObject, KMethodName_To(KType_Function), 0,
		//_Public|_Const|_Im|_Coercion, _F(Function_toPyObject), KType_PyObject, KType_Function, KMethodName_To(KType_PyObject), 0,
		//_Public|_Const|_Im|_Coercion, _F(PyObject_asMethod), KType_Method, KType_PyObject, KMethodName_To(KType_Method), 0,
		//_Public|_Const|_Im|_Coercion, _F(Method_toPyObject), KType_PyObject, KType_Method, KMethodName_To(KType_PyObject), 0,
		//_Public|_Const|_Im|_Coercion, _F(PyObject_toFile), KType_File, KType_PyObject, KMethodName_To(KType_File), 0,
		//_Public|_Const|_Im|_Coercion, _F(File_toPyObject), KType_PyObject, KType_File, KMethodName_To(KType_PyObject), 0,
		//_Public|_Const|_Im|_Coercion, _F(PyObject_toModule), KType_Module, KType_PyObject, KMethodName_To(KType_Module), 0,
		//_Public|_Const|_Im|_Coercion, _F(Module_toPyObject), KType_PyObject, KType_Module, KMethodName_To(KType_PyObject), 0,
		//_Public|_Const|_Im|_Coercion, _F(PyObject_toSeqIter), KType_SeqIter, KType_PyObject, KMethodName_To(KType_SeqIter), 0,
		//_Public|_Const|_Im|_Coercion, _F(SeqIter_toPyObject), KType_PyObject, KType_SeqIter, KMethodName_To(KType_PyObject), 0,
		//_Public|_Const|_Im|_Coercion, _F(PyObject_toSlice), KType_Slice, KType_PyObject, KMethodName_To(KType_Slice), 0,
		//_Public|_Const|_Im|_Coercion, _F(Slice_toPyObject), KType_PyObject, KType_Slice, KMethodName_To(KType_PyObject), 0,
		//_Public|_Const|_Im|_Coercion, _F(PyObject_toWeakref), KType_Weakref, KType_PyObject, KMethodName_To(KType_Weakref), 0,
		//_Public|_Const|_Im|_Coercion, _F(Weakref_toPyObject), KType_PyObject, KType_Weakref, KMethodName_To(KType_PyObject), 0,
		//_Public|_Const|_Im|_Coercion, _F(PyObject_toCapsule), KType_Capsule, KType_PyObject, KMethodName_To(KType_Capsule), 0,
		//_Public|_Const|_Im|_Coercion, _F(Capsule_toPyObject), KType_PyObject, KType_Capsule, KMethodName_To(KType_PyObject), 0,
		//_Public|_Const|_Im|_Coercion, _F(PyObject_toCell), KType_Cell, KType_PyObject, KMethodName_To(KType_Cell), 0,
		//_Public|_Const|_Im|_Coercion, _F(Cell_toPyObject), KType_PyObject, KType_Cell, KMethodName_To(KType_PyObject), 0,
		//_Public|_Const|_Im|_Coercion, _F(PyObject_toGen), KType_Gen, KType_PyObject, KMethodName_To(KType_Gen), 0,
		//_Public|_Const|_Im|_Coercion, _F(Gen_toPyObject), KType_PyObject, KType_Gen, KMethodName_To(KType_PyObject), 0,
		//_Public|_Const|_Im|_Coercion, _F(Date_toPyObject), KType_PyObject, KType_Date, KMethodName_To(KType_PyObject), 0,
		//_Public|_Const|_Im|_Coercion, _F(PyObject_toDate), KType_Date, KType_PyObject, KMethodName_To(KType_Date), 0,
		//_Public|_Const|_Im|_Coercion, _F(Set_toPyObject), KType_PyObject, KType_Set, KMethodName_To(KType_PyObject), 0,
		//_Public|_Const|_Im|_Coercion, _F(PyObject_toSet), KType_Set, KType_PyObject, KMethodName_To(KType_Set), 0,
		//_Public|_Const|_Im|_Coercion, _F(Code_toPyObject), KType_PyObject, KType_Code, KMethodName_To(KType_PyObject), 0,
		//_Public|_Const|_Im|_Coercion, _F(PyObject_toCode), KType_Code, KType_PyObject, KMethodName_To(KType_Code), 0,
		_Public|_Im, _F(Python_Eval), KType_Boolean, KType_System, KFieldName_("pyEval"), 1, KType_String, KFieldName_("script"),
		_Public|_Im, _F(PyObject_import), KType_PyObject, KType_PyObject, KFieldName_("import"), 1, KType_String, KFieldName_("name"),
		_Public|_Im, _F(PyObject_), KType_PyObject, KType_PyObject, 0, 1, KType_PyObject, 0,
		DEND,
	};
	KLIB kNameSpace_LoadMethodData(kctx, ns, MethodData, trace);
	if(KDefinedKonohaCommonModule() == true && KClass_Float != NULL) {
		KDEFINE_METHOD MethodData[] = {
			_Public|_Const|_Im|_Coercion, _F(PyObject_toFloat), KType_float, KType_PyObject, KMethodName_To(KType_float), 0,
			_Public|_Const|_Im|_Coercion, _F(Float_toPyObject), KType_PyObject, KType_float, KMethodName_To(KType_PyObject), 0,
			DEND,
		};
		KLIB kNameSpace_LoadMethodData(kctx, ns, MethodData, trace);
	}
	return true;
}
Beispiel #29
0
		STRUCTNAME(AprTableEntry),
		.init = AprTableEntry_Init,
		.free = AprTableEntry_Free,
	};

	static KDEFINE_CLASS apacheDef = {
		STRUCTNAME(Apache),
	};

	KModuleApache *mod = (KModuleApache *)KCalloc_UNTRACE(sizeof(KModuleApache), 1);
	mod->h.name               = "apache";
	mod->h.allocSize          = sizeof(KModuleApache);
	mod->h.setupModuleContext = ApacheModule_Setup;
	mod->h.freeModule         = ApacheModule_Free;
	KLIB KonohaRuntime_setModule(kctx, MOD_APACHE, (KonohaModule *)mod, trace);
	mod->cRequest       = KLIB kNameSpace_DefineClass(kctx, ns, NULL, &Def, 0);
	mod->cAprTable      = KLIB kNameSpace_DefineClass(kctx, ns, NULL, &aprTableDef, 0);
	mod->cAprTableEntry = KLIB kNameSpace_DefineClass(kctx, ns, NULL, &aprTableEntryDef, 0);
	mod->cApache        = KLIB kNameSpace_DefineClass(kctx, ns, NULL, &apacheDef, 0);

	KDEFINE_INT_CONST IntData[] = {
#define DEFINE_KEYWORD(KW) {#KW, TY_int, KW}
		DEFINE_KEYWORD(OK),
		DEFINE_KEYWORD(APLOG_EMERG),
		DEFINE_KEYWORD(APLOG_ALERT),
		DEFINE_KEYWORD(APLOG_CRIT),
		DEFINE_KEYWORD(APLOG_ERR),
		DEFINE_KEYWORD(APLOG_WARNING),
		DEFINE_KEYWORD(APLOG_NOTICE),
		DEFINE_KEYWORD(APLOG_INFO),
		DEFINE_KEYWORD(APLOG_DEBUG),
Beispiel #30
0
static kbool_t Complex_PackupNameSpace(KonohaContext *kctx, kNameSpace *ns, int option, KTraceInfo *trace)
{
	KRequirePackage("Type.Float", trace);
	KDEFINE_CLASS defComplex = {0};
	SETSTRUCTNAME(defComplex, Complex);
	defComplex.cflag     = KClassFlag_Final;
	defComplex.init      = kComplex_Init;
	defComplex.free      = kComplex_Free;
	KClass *ComplexClass = KLIB kNameSpace_DefineClass(kctx, ns, NULL, &defComplex, trace);

	int KType_Complex = ComplexClass->typeId;
	KDEFINE_METHOD MethodData[] = {
		_Public, _F(Complex_new),     KType_Complex, KType_Complex, KMethodName_("new"),   2, KType_float, KFieldName_("real"), KType_float, KFieldName_("imaginary"),
		_Public, _F(Complex_csin),    KType_float, KType_Complex, KMethodName_("csin"),    0,
		_Public, _F(Complex_csinf),   KType_float, KType_Complex, KMethodName_("csinf"),   0,
		_Public, _F(Complex_csinl),   KType_float, KType_Complex, KMethodName_("csinl"),   0,
		_Public, _F(Complex_ccos),    KType_float, KType_Complex, KMethodName_("ccos"),    0,
		_Public, _F(Complex_ccosf),   KType_float, KType_Complex, KMethodName_("ccosf"),   0,
		_Public, _F(Complex_ccosl),   KType_float, KType_Complex, KMethodName_("ccosl"),   0,
		_Public, _F(Complex_ctan),    KType_float, KType_Complex, KMethodName_("ctan"),    0,
		_Public, _F(Complex_ctanf),   KType_float, KType_Complex, KMethodName_("ctanf"),   0,
		_Public, _F(Complex_ctanl),   KType_float, KType_Complex, KMethodName_("ctanl"),   0,
		_Public, _F(Complex_casin),   KType_float, KType_Complex, KMethodName_("casin"),   0,
		_Public, _F(Complex_casinf),  KType_float, KType_Complex, KMethodName_("casinf"),  0,
		_Public, _F(Complex_casinl),  KType_float, KType_Complex, KMethodName_("casinl"),  0,
		_Public, _F(Complex_cacos),   KType_float, KType_Complex, KMethodName_("cacos"),   0,
		_Public, _F(Complex_cacosf),  KType_float, KType_Complex, KMethodName_("cacosf"),  0,
		_Public, _F(Complex_cacosl),  KType_float, KType_Complex, KMethodName_("cacosl"),  0,
		_Public, _F(Complex_catan),   KType_float, KType_Complex, KMethodName_("catan"),   0,
		_Public, _F(Complex_catanf),  KType_float, KType_Complex, KMethodName_("catanf"),  0,
		_Public, _F(Complex_catanl),  KType_float, KType_Complex, KMethodName_("catanl"),  0,
		_Public, _F(Complex_csinh),   KType_float, KType_Complex, KMethodName_("csinh"),   0,
		_Public, _F(Complex_csinhf),  KType_float, KType_Complex, KMethodName_("csinhf"),  0,
		_Public, _F(Complex_csinhl),  KType_float, KType_Complex, KMethodName_("csinhl"),  0,
		_Public, _F(Complex_ccosh),   KType_float, KType_Complex, KMethodName_("ccosh"),   0,
		_Public, _F(Complex_ccoshf),  KType_float, KType_Complex, KMethodName_("ccoshf"),  0,
		_Public, _F(Complex_ccoshl),  KType_float, KType_Complex, KMethodName_("ccoshl"),  0,
		_Public, _F(Complex_ctanh),   KType_float, KType_Complex, KMethodName_("ctanh"),   0,
		_Public, _F(Complex_ctanhf),  KType_float, KType_Complex, KMethodName_("ctanhf"),  0,
		_Public, _F(Complex_ctanhl),  KType_float, KType_Complex, KMethodName_("ctanhl"),  0,
		_Public, _F(Complex_casinh),  KType_float, KType_Complex, KMethodName_("casinh"),  0,
		_Public, _F(Complex_casinhf), KType_float, KType_Complex, KMethodName_("casinhf"), 0,
		_Public, _F(Complex_casinhl), KType_float, KType_Complex, KMethodName_("casinhl"), 0,
		_Public, _F(Complex_cacosh),  KType_float, KType_Complex, KMethodName_("cacosh"),  0,
		_Public, _F(Complex_cacoshf), KType_float, KType_Complex, KMethodName_("cacoshf"), 0,
		_Public, _F(Complex_cacoshl), KType_float, KType_Complex, KMethodName_("cacoshl"), 0,
		_Public, _F(Complex_catanh),  KType_float, KType_Complex, KMethodName_("catanh"),  0,
		_Public, _F(Complex_catanhf), KType_float, KType_Complex, KMethodName_("catanhf"), 0,
		_Public, _F(Complex_catanhl), KType_float, KType_Complex, KMethodName_("catanhl"), 0,
		_Public, _F(Complex_cexp),    KType_float, KType_Complex, KMethodName_("cexp"),    0,
		_Public, _F(Complex_cexpf),   KType_float, KType_Complex, KMethodName_("cexpf"),   0,
		_Public, _F(Complex_cexpl),   KType_float, KType_Complex, KMethodName_("cexpl"),   0,
		_Public, _F(Complex_clog),    KType_float, KType_Complex, KMethodName_("clog"),    0,
		_Public, _F(Complex_clogf),   KType_float, KType_Complex, KMethodName_("clogf"),   0,
		_Public, _F(Complex_clogl),   KType_float, KType_Complex, KMethodName_("clogl"),   0,
		_Public, _F(Complex_cabs),    KType_float, KType_Complex, KMethodName_("cabs"),    0,
		_Public, _F(Complex_cabsf),   KType_float, KType_Complex, KMethodName_("cabsf"),   0,
		_Public, _F(Complex_cabsl),   KType_float, KType_Complex, KMethodName_("cabsl"),   0,
		_Public, _F(Complex_csqrt),   KType_float, KType_Complex, KMethodName_("csqrt"),   0,
		_Public, _F(Complex_csqrtf),  KType_float, KType_Complex, KMethodName_("csqrtf"),  0,
		_Public, _F(Complex_csqrtl),  KType_float, KType_Complex, KMethodName_("csqrtl"),  0,
		_Public, _F(Complex_cpow),    KType_float, KType_Complex, KMethodName_("cpow"),    2, KType_float,   KFieldName_("real"), KType_float, KFieldName_("imaginary"),
		_Public, _F(Complex_cpowf),   KType_float, KType_Complex, KMethodName_("cpowf"),   2, KType_float,   KFieldName_("real"), KType_float, KFieldName_("imaginary"),
		_Public, _F(Complex_cpowl),   KType_float, KType_Complex, KMethodName_("cpowl"),   2, KType_float,   KFieldName_("real"), KType_float, KFieldName_("imaginary"),
		_Public, _F(Complex_creal),   KType_float, KType_Complex, KMethodName_("creal"),   0,
		_Public, _F(Complex_crealf),  KType_float, KType_Complex, KMethodName_("crealf"),  0,
		_Public, _F(Complex_creall),  KType_float, KType_Complex, KMethodName_("creall"),  0,
		_Public, _F(Complex_cimag),   KType_float, KType_Complex, KMethodName_("cimag"),   0,
		_Public, _F(Complex_cimagf),  KType_float, KType_Complex, KMethodName_("cimagf"),  0,
		_Public, _F(Complex_cimagl),  KType_float, KType_Complex, KMethodName_("cimagl"),  0,
		_Public, _F(Complex_carg),    KType_float, KType_Complex, KMethodName_("carg"),    0,
		_Public, _F(Complex_cargf),   KType_float, KType_Complex, KMethodName_("cargf"),   0,
		_Public, _F(Complex_cargl),   KType_float, KType_Complex, KMethodName_("cargl"),   0,
		_Public, _F(Complex_conj),    KType_Complex, KType_Complex, KMethodName_("conj"),  0,
		_Public, _F(Complex_conjf),   KType_Complex, KType_Complex, KMethodName_("conjf"), 0,
		_Public, _F(Complex_conjl),   KType_Complex, KType_Complex, KMethodName_("conjl"), 0,
		DEND, /* <= sentinel */
	};
	KLIB kNameSpace_LoadMethodData(kctx, ns, MethodData, trace);

	return true;
}