Beispiel #1
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 #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 prototype_PackupNameSpace(KonohaContext *kctx, kNameSpace *ns, int option, KTraceInfo *trace)
{
	KRequireKonohaCommonModule(trace);
	prototype_defineClass(kctx, ns, option, trace);
	prototype_defineMethod(kctx, ns, trace);
	return true;
}
Beispiel #4
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 #5
0
static kbool_t array_defineMethod(KonohaContext *kctx, kNameSpace *ns, KTraceInfo *trace)
{
	KRequireKonohaCommonModule(trace);
	KImportPackageSymbol(ns, "cstyle", "[]", trace);
	KDEFINE_INT_CONST ClassData[] = {   // add Array as available
		{"Array", VirtualType_KonohaClass, (uintptr_t)CT_(TY_Array)},
		{NULL},
	};
	KLIB kNameSpace_LoadConstData(kctx, ns, KonohaConst_(ClassData), false/*isOverride*/, trace);

	KonohaClass *CT_ArrayT0 = CT_p0(kctx, CT_Array, TY_0);
	kattrtype_t TY_ArrayT0 = CT_ArrayT0->typeId;

	kparamtype_t p[] = {{TY_0}};
	kattrtype_t TY_FuncMap = (KLIB KonohaClass_Generics(kctx, CT_Func, TY_0 , 1, p))->typeId;

	kparamtype_t P_inject[] = {{TY_0},{TY_0}};
	kattrtype_t TY_FuncInject = (KLIB KonohaClass_Generics(kctx, CT_Func, TY_0 , 2, P_inject))->typeId;

	KDEFINE_METHOD MethodData[] = {
		_Public|_Im,    _F(Array_get), TY_0,   TY_Array, MN_("get"), 1, TY_int, FN_("index"),
		_Public,        _F(Array_set), TY_void, TY_Array, MN_("set"), 2, TY_int, FN_("index"),  TY_0, FN_("value"),
		_Public|_Im,    _F(Array_removeAt), TY_0,   TY_Array, MN_("removeAt"), 1, TY_int, FN_("index"),
		_Public|_Const, _F(Array_getSize), TY_int, TY_Array, MN_("getSize"), 0,
		_Public|_Const, _F(Array_getSize), TY_int, TY_Array, MN_("getlength"), 0,
		_Public,        _F(Array_clear), TY_void, TY_Array, MN_("clear"), 0,
		_Public,        _F(Array_Add1), TY_void, TY_Array, MN_("add"), 1, TY_0, FN_("value"),
		_Public,        _F(Array_Push), TY_int, TY_Array, MN_("push"), 1, TY_0, FN_("value"),
		_Public,        _F(Array_Pop), TY_0, TY_Array, MN_("pop"), 0,
		_Public,        _F(Array_shift), TY_0, TY_Array, MN_("shift"), 0,
		_Public,        _F(Array_unshift), TY_int, TY_Array, MN_("unshift"), 1, TY_0, FN_("value"),
		_Public,        _F(Array_reverse), TY_Array, TY_Array, MN_("reverse"), 0,
//		_Public|_Im,    _F(Array_map), TY_ArrayT0, TY_Array, MN_("map"), 1, TY_FuncMap, FN_("func"),
//		_Public|_Im,    _F(Array_inject), TY_0, TY_Array, MN_("inject"), 1, TY_FuncInject, FN_("func"),

		_Public,        _F(Array_concat), TY_ArrayT0, TY_Array, MN_("concat"), 1, TY_ArrayT0, FN_("a1"),
		_Public,        _F(Array_indexOf), TY_int, TY_Array, MN_("indexOf"), 1, TY_0, FN_("value"),
		_Public,        _F(Array_lastIndexOf), TY_int, TY_Array, MN_("lastIndexOf"), 1, TY_0, FN_("value"),
//		_Public,        _F(Array_toString), TY_String, TY_Array, MN_("toString"), 0,
		_Public|_Im,    _F(Array_new), TY_void, TY_Array, MN_("new"), 1, TY_int, FN_("size"),
		_Public,        _F(Array_newArray), TY_Array, TY_Array, MN_("newArray"), 1, TY_int, FN_("size"),
		_Public|kMethod_Hidden, _F(Array_newList), TY_Array, TY_Array, MN_("[]"), 0,
		DEND,
	};
	KLIB kNameSpace_LoadMethodData(kctx, ns, MethodData, trace);
	return true;
}
Beispiel #6
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 #7
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;
}