コード例 #1
0
ファイル: hello_world_glue.c プロジェクト: hisaboh/minikonoha
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;
}
コード例 #2
0
ファイル: File_glue.c プロジェクト: imasahiro/konoha3
static kbool_t file_ExportNameSpace(KonohaContext *kctx, kNameSpace *ns, kNameSpace *exportNS, int option, KTraceInfo *trace)
{
	KDEFINE_INT_CONST ClassData[] = {   // add Array as available
		{"FILE", VirtualType_KClass, (uintptr_t)KClass_File},
		{NULL},
	};
	KLIB kNameSpace_LoadConstData(kctx, exportNS, KConst_(ClassData), trace);
	return true;
}
コード例 #3
0
ファイル: var_glue.c プロジェクト: kkuramitsu/minikonoha
static kbool_t var_PackupNameSpace(KonohaContext *kctx, kNameSpace *ns, int option, KTraceInfo *trace)
{
	KDEFINE_INT_CONST ClassData[] = {   // add Array as available
		{"var", VirtualType_KonohaClass, (uintptr_t)CT_(TY_var)},
		{NULL},
	};
	KLIB kNameSpace_LoadConstData(kctx, ns, KonohaConst_(ClassData), trace);
	return true;
}
コード例 #4
0
ファイル: File_glue.c プロジェクト: imasahiro/konoha3
static void file_defineConst(KonohaContext *kctx, kNameSpace *ns, KTraceInfo *trace)
{
	KFileStdIn  = new_File(kctx, OnGlobalConstList, stdin, TEXTSIZE("/dev/stdin"), trace);
	KFileStdOut = new_File(kctx, OnGlobalConstList, stdout, TEXTSIZE("/dev/stdout"), trace);
	KFileStdErr = new_File(kctx, OnGlobalConstList, stderr, TEXTSIZE("/dev/stderr"), trace);
	KDEFINE_FILE_CONST FileData[] = {
		{"stdin", KType_File,  KFileStdIn},
		{"stdout", KType_File, KFileStdOut},
		{"stderr", KType_File, KFileStdErr},
		{NULL}, /* sentinel */
	};
	KLIB kNameSpace_LoadConstData(kctx, ns, KConst_(FileData), trace);
	KDEFINE_INT_CONST IntData[] = {
		{"EOF", KType_Int,  EOF},
		{NULL}, /* sentinel */
	};
	KLIB kNameSpace_LoadConstData(kctx, ns, KConst_(IntData), trace);

}
コード例 #5
0
static kbool_t float_ExportNameSpace(KonohaContext *kctx, kNameSpace *ns, kNameSpace *exportNS, int option, KTraceInfo *trace)
{
	if(sizeof(kfloat_t) == sizeof(double)) {
		KDEFINE_INT_CONST ClassData[] = {   // add Array as available
			{"double", VirtualType_KClass, (uintptr_t)KClass_Float},
			{NULL},
		};
		KLIB kNameSpace_LoadConstData(kctx, exportNS, KConst_(ClassData), trace);
	}
	return true;
}
コード例 #6
0
ファイル: path_glue.c プロジェクト: Kouhei-Moriya/konoha3
static void path_defineAccessConst(KonohaContext *kctx, kNameSpace *ns, KTraceInfo *trace)
{
	KDEFINE_INT_CONST intData[] = {
		/*for System.access*/
		{KDefineConstInt(R_OK)},
		{KDefineConstInt(W_OK)},
		{KDefineConstInt(X_OK)},
		{KDefineConstInt(F_OK)},
		{NULL} /* sentinel */
	};
	KLIB kNameSpace_LoadConstData(kctx, ns, KConst_(intData), trace);
}
コード例 #7
0
ファイル: object_glue.c プロジェクト: doly/minikonoha
static kbool_t object_PackupNameSpace(KonohaContext *kctx, kNameSpace *ns, int option, KTraceInfo *trace)
{
//	KRequirePackage("konoha.subtype", trace);
	KDEFINE_INT_CONST ClassData[] = {   // add Object as available
		{"Object", VirtualType_KonohaClass, (uintptr_t)CT_(TY_Object)},
		{NULL},
	};
	KLIB kNameSpace_LoadConstData(kctx, ns, KonohaConst_(ClassData), false/*isOverride*/, trace);
	object_defineMethod(kctx, ns, trace);
	subtype_defineSyntax(kctx, ns, trace);
	return true;
}
コード例 #8
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;
}
コード例 #9
0
ファイル: sugar_glue.c プロジェクト: kkuramitsu/minikonoha
static kbool_t RENAMEME_InitNameSpace(KonohaContext *kctx, kNameSpace *packageNS, kNameSpace *ns, KTraceInfo *trace)
{
	KDEFINE_INT_CONST IntData[] = {
#define DEFINE_KEYWORD(KW) {#KW, TY_int, KW}
		DEFINE_KEYWORD(KW_ExprPattern),
		DEFINE_KEYWORD(KW_SymbolPattern),
		DEFINE_KEYWORD(KW_TextPattern),
		DEFINE_KEYWORD(KW_NumberPattern),
		DEFINE_KEYWORD(KW_TypePattern),
		DEFINE_KEYWORD(KW_ParenthesisGroup),
		DEFINE_KEYWORD(KW_BracketGroup),
		DEFINE_KEYWORD(KW_BraceGroup),
		DEFINE_KEYWORD(KW_BlockPattern),
		DEFINE_KEYWORD(KW_ParamPattern),
		DEFINE_KEYWORD(KW_TokenPattern),
		DEFINE_KEYWORD(TSTMT_UNDEFINED),
		DEFINE_KEYWORD(TSTMT_ERR),
		DEFINE_KEYWORD(TSTMT_EXPR),
		DEFINE_KEYWORD(TSTMT_BLOCK),
		DEFINE_KEYWORD(TSTMT_RETURN),
		DEFINE_KEYWORD(TSTMT_IF),
		DEFINE_KEYWORD(TSTMT_LOOP),
		DEFINE_KEYWORD(TSTMT_JUMP),
		DEFINE_KEYWORD(TEXPR_CONST),
		DEFINE_KEYWORD(TEXPR_NEW),
		DEFINE_KEYWORD(TEXPR_NULL),
		DEFINE_KEYWORD(TEXPR_NCONST),
		DEFINE_KEYWORD(TEXPR_LOCAL),
		DEFINE_KEYWORD(TEXPR_BLOCK),
		DEFINE_KEYWORD(TEXPR_FIELD),
//		DEFINE_KEYWORD(TEXPR_BOX),
//		DEFINE_KEYWORD(TEXPR_UNBOX),
		DEFINE_KEYWORD(TEXPR_CALL),
		DEFINE_KEYWORD(TEXPR_AND),
		DEFINE_KEYWORD(TEXPR_OR),
		DEFINE_KEYWORD(TEXPR_LET),
		DEFINE_KEYWORD(TEXPR_STACKTOP),
		DEFINE_KEYWORD(TypeCheckPolicy_NOCHECK),
		DEFINE_KEYWORD(TypeCheckPolicy_ALLOWVOID),
		DEFINE_KEYWORD(TypeCheckPolicy_COERCION),
		DEFINE_KEYWORD(TypeCheckPolicy_CONST),
#undef DEFINE_KEYWORD
		{NULL},
	};
	KLIB kNameSpace_LoadConstData(kctx, ns, KonohaConst_(IntData), trace);
	KDEFINE_SYNTAX SYNTAX[] = {
		{ SYM_("syntax"), 0, "\"syntax\" $Token*", 0, 0, NULL, NULL, Statement_syntax, NULL, NULL, },
		{ KW_END, },
	};
	SUGAR kNameSpace_DefineSyntax(kctx, ns, SYNTAX, trace);
	return true;
}
コード例 #10
0
ファイル: process_glue.c プロジェクト: myoan/minikonoha
static kbool_t process_PackupNameSpace(KonohaContext *kctx, kNameSpace *ns, int option, KTraceInfo *trace)
{
	kparamtype_t p = {KType_Int};
	KClass *cintArray = KLIB KClass_Generics(kctx, KClass_(KType_Array), KType_void, 1, &p);
#define KType_IntArray (cintArray->typeId)

	KDEFINE_METHOD MethodData[] = {
		_Public|_Static, _F(System_getpid), KType_Int, KType_System, KMethodName_("getpid"), 0,
		_Public|_Static, _F(System_getppid), KType_Int, KType_System, KMethodName_("getppid"), 0,
		_Public|_Static, _F(System_getuid), KType_Int, KType_System, KMethodName_("getuid"), 0,
		_Public|_Static, _F(System_geteuid), KType_Int, KType_System, KMethodName_("geteuid"), 0,
		_Public|_Static, _F(System_getgid), KType_Int, KType_System, KMethodName_("getgid"), 0,
		_Public|_Static, _F(System_getegid), KType_Int, KType_System, KMethodName_("getegid"), 0,
		_Public|_Static, _F(System_getpgid), KType_Int, KType_System, KMethodName_("getpgid"), 1, KType_Int, KFieldName_("pid"),
		_Public|_Static, _F(System_Setpgid), KType_Int, KType_System, KMethodName_("setpgid"), 2, KType_Int, KFieldName_("pid"), KType_Int, KFieldName_("pgid"),
		_Public|_Static, _F(System_getpriority), KType_Int, KType_System, KMethodName_("getpriority"), 2, KType_Int, KFieldName_("which"), KType_Int, KFieldName_("who"),
		_Public|_Static, _F(System_Setpriority), KType_Int, KType_System, KMethodName_("setpriority"), 3, KType_Int, KFieldName_("which"), KType_Int, KFieldName_("who"), KType_Int, KFieldName_("priority"),
		_Public|_Static, _F(System_getgroups), KType_Int, KType_System, KMethodName_("getgroups"), 2, KType_Int, KFieldName_("size"), KType_IntArray, KFieldName_("list[]"),
		_Public|_Static, _F(System_Setgroups), KType_Int, KType_System, KMethodName_("setgroups"), 2, KType_Int, KFieldName_("size"), KType_IntArray, KFieldName_("*list"),
		_Public|_Static, _F(System_fork), KType_Int, KType_System, KMethodName_("fork"), 0,
		_Public|_Static, _F(System_wait), KType_Int, KType_System, KMethodName_("wait"), 0,
		_Public|_Static, _F(System_waitpid), KType_Int, KType_System, KMethodName_("wait"), 2, KType_Int, KFieldName_("pid"), KType_Int, KFieldName_("options"),
		_Public|_Static, _F(System_Setuid), KType_Int, KType_System, KMethodName_("setuid"), 1, KType_Int, KFieldName_("uid"),
		_Public|_Static, _F(System_Seteuid), KType_Int, KType_System, KMethodName_("seteuid"), 1, KType_Int, KFieldName_("euid"),
		_Public|_Static, _F(System_Setreuid), KType_Int, KType_System, KMethodName_("setreuid"), 2, KType_Int, KFieldName_("ruid"), KType_Int, KFieldName_("euid"),
		_Public|_Static, _F(System_Setgid), KType_Int, KType_System, KMethodName_("setgid"), 1, KType_Int, KFieldName_("gid"),
		_Public|_Static, _F(System_Setegid), KType_Int, KType_System, KMethodName_("setguid"), 1, KType_Int, KFieldName_("egid"),
		_Public|_Static, _F(System_Setregid), KType_Int, KType_System, KMethodName_("setrguid"), 2, KType_Int, KFieldName_("rgid"), KType_Int, KFieldName_("egid"),
		_Public|_Static, _F(System_Setsid), KType_Int, KType_System, KMethodName_("setsid"), 0,
		_Public|_Static, _F(System_getsid), KType_Int, KType_System, KMethodName_("getsid"), 1, KType_Int, KFieldName_("pid"),
		_Public|_Static, _F(System_sleep), KType_Int, KType_System, KMethodName_("sleep"), 1, KType_Int, KFieldName_("sec"),
		_Public|_Static, _F(System_usleep), KType_Boolean, KType_System, KMethodName_("usleep"), 1, KType_Int, KFieldName_("usec"),
		_Public|_Static, _F(System_system), KType_Int, KType_System, KMethodName_("system"), 1, KType_String, KFieldName_("command"),
		_Public|_Static, _F(System_getenv), KType_String, KType_System, KMethodName_("getenv"), 1, KType_String, KFieldName_("name"),
		DEND,
	};
	KLIB kNameSpace_LoadMethodData(kctx, ns, MethodData, trace);
	KDEFINE_INT_CONST intData[] = {
		{KDefineConstInt(SIGHUP)},
		{KDefineConstInt(SIGINT)},
		{KDefineConstInt(SIGABRT)},
		{KDefineConstInt(SIGKILL)},
		/*for System.setpriority*/
		{KDefineConstInt(PRIO_PROCESS)},
		{KDefineConstInt(PRIO_PGRP)},
		{KDefineConstInt(PRIO_USER)},
		{}
	};
	KLIB kNameSpace_LoadConstData(kctx, ns, KConst_(intData), trace);
	return true;
}
コード例 #11
0
ファイル: sugar_glue.c プロジェクト: kkuramitsu/minikonoha
static kbool_t sugar_ExportNameSpace(KonohaContext *kctx, kNameSpace *ns, kNameSpace *exportNS, int option, KTraceInfo *trace)
{
	KDEFINE_INT_CONST IntData[] = {
#define DEFINE_KEYWORD(KW) {#KW, TY_int, KW}
		DEFINE_KEYWORD(ErrTag),
		DEFINE_KEYWORD(WarnTag),
		DEFINE_KEYWORD(NoticeTag),
		DEFINE_KEYWORD(InfoTag),
		DEFINE_KEYWORD(DebugTag),
#undef DEFINE_KEYWORD
		{NULL},
	};
	KLIB kNameSpace_LoadConstData(kctx, exportNS, KonohaConst_(IntData), trace);
	return true;
}
コード例 #12
0
ファイル: array_glue.c プロジェクト: hisaboh/minikonoha
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;
}
コード例 #13
0
ファイル: class_glue.c プロジェクト: doly/minikonoha
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;
}
コード例 #14
0
ファイル: fd_glue.c プロジェクト: kkuramitsu/minikonoha
static kbool_t fd_PackupNameSpace(KonohaContext *kctx, kNameSpace *ns, int option, KTraceInfo *trace)
{
	KDEFINE_METHOD MethodData[] = {
		_Public|_Static, _F(System_lseek),     TY_int,     TY_System, MN_("lseek"),     3, TY_int, FN_("fd"), TY_int, FN_("offset"), TY_int, FN_("whence"),
		_Public|_Static, _F(System_ftruncate), TY_boolean, TY_System, MN_("ftruncate"), 2, TY_int, FN_("fd"), TY_int, FN_("length"),
		_Public|_Static, _F(System_fchmod),    TY_boolean, TY_System, MN_("fchmod"),    2, TY_int, FN_("fd"), TY_int, FN_("length"),
		_Public|_Static, _F(System_flock),     TY_boolean, TY_System, MN_("flock"),     2, TY_int, FN_("fd"), TY_int, FN_("operation"),
		_Public|_Static, _F(System_sync),      TY_boolean, TY_System, MN_("sync"),      1, TY_int, FN_("fd"),
		_Public|_Static, _F(System_fchown),    TY_boolean, TY_System, MN_("fchown"),    3, TY_int, FN_("pd"), TY_int, FN_("owner"),  TY_int, FN_("group"),
		_Public|_Static, _F(System_fsync),     TY_boolean, TY_System, MN_("fsync"),     1, TY_int, FN_("fd"),
		_Public|_Static|_Const|_Im, _F(System_getdtablesize), TY_int, TY_System, MN_("getdtablesize"), 0,
		_Public|_Static|_Im, _F(System_open),      TY_int,     TY_System, MN_("open"),   2, TY_String, FN_("pathname"), TY_int, FN_("flags"),
		_Public|_Static|_Im, _F(System_open_mode), TY_int,     TY_System, MN_("open"),   3, TY_String, FN_("pathname"), TY_int, FN_("flags"), TY_int, FN_("mode"),
		_Public|_Static|_Im, _F(System_fchdir),    TY_boolean, TY_System, MN_("fchdir"), 1, TY_int,    FN_("fd"),
		_Public|_Static|_Im, _F(System_isatty),    TY_boolean, TY_System, MN_("isatty"), 1, TY_int,    FN_("fd"),
		_Public|_Static|_Im, _F(System_ttyname),   TY_String, TY_System, MN_("ttyname"), 1, TY_int,    FN_("fd"),
		DEND,
	};
	KLIB kNameSpace_LoadMethodData(kctx, ns, MethodData, trace);
	KDEFINE_INT_CONST intData[] = {
		/*for System.lseek*/
		{KDefineConstInt(SEEK_SET)},
		{KDefineConstInt(SEEK_CUR)},
		{KDefineConstInt(SEEK_END)},
		/*for System.flock*/
		{KDefineConstInt(LOCK_SH)},
		{KDefineConstInt(LOCK_EX)},
		{KDefineConstInt(LOCK_UN)},
		{KDefineConstInt(LOCK_NB)},
		/*for System.open*/
		{KDefineConstInt(O_RDONLY)},
		{KDefineConstInt(O_WRONLY)},
		{KDefineConstInt(O_RDWR)},
		{KDefineConstInt(O_CREAT)},
		{KDefineConstInt(O_EXCL)},
		{KDefineConstInt(O_TRUNC)},
		{KDefineConstInt(O_APPEND)},
		{KDefineConstInt(O_NONBLOCK)},
		{KDefineConstInt(O_NDELAY)},
		{KDefineConstInt(O_NOCTTY)},
		{NULL}, /* sentinel */
	};
	KLIB kNameSpace_LoadConstData(kctx, ns, KonohaConst_(intData), 0);
	return true;
}
コード例 #15
0
ファイル: Syntax_glue.c プロジェクト: myoan/minikonoha
static kbool_t Syntax_PackupNameSpace(KonohaContext *kctx, kNameSpace *ns, int option, KTraceInfo *trace)
{
	KDEFINE_INT_CONST ClassData[] = {   // add Array as available
		{"Symbol", VirtualType_KClass, (uintptr_t)KClass_Symbol},
		{"Syntax",   VirtualType_KClass,  (uintptr_t)KClass_Syntax},
		{"Token",  VirtualType_KClass, (uintptr_t)KClass_Token},
		{"Node",   VirtualType_KClass,  (uintptr_t)KClass_Node},
		{"NameSpace", VirtualType_KClass, (uintptr_t)KClass_NameSpace},
		{NULL},
	};
	KLIB kNameSpace_LoadConstData(kctx, ns, KConst_(ClassData), 0);
	Syntax_defineTokenFunc(kctx, ns, trace);
	Syntax_defineMessageMethod(kctx, ns, trace);
	Syntax_defineNodeMethod(kctx, ns, trace);
	Syntax_defineSyntaxMethod(kctx, ns, trace);
	Syntax_defineNameSpaceMethod(kctx, ns, trace);
	return true;
}
コード例 #16
0
ファイル: parser.c プロジェクト: masakiishii/konoha.js
void MODSUGAR_Init(KonohaContext *kctx, KonohaContextVar *ctx)
{
	KParserModel *mod = (KParserModel *)KCalloc_UNTRACE(sizeof(KParserModel), 1);
	mod->h.name     = "sugar";
	mod->h.allocSize = sizeof(KParserModel);
	mod->h.setupModelContext    = SugarModule_Setup;
	KLIB KRuntime_SetModule(kctx, ParserModelIndex, (KRuntimeModel *)mod, 0);

	KonohaLibVar *l = (KonohaLibVar *)ctx->klib;
	l->kNameSpace_GetClassByFullName  = kNameSpace_GetClassByFullName;
	l->kNameSpace_DefineClass    = kNameSpace_DefineClass;
	l->kNameSpace_LoadMethodData = kNameSpace_LoadMethodData;
	l->kNameSpace_SetConstData   = kNameSpace_SetConstData;
	l->kNameSpace_LoadConstData  = kNameSpace_LoadConstData;
	l->kNameSpace_GetGetterMethodNULL  = kNameSpace_GetGetterMethodNULL;
	l->kNameSpace_GetSetterMethodNULL  = kNameSpace_GetSetterMethodNULL;
	l->kNameSpace_GetCoercionMethodNULL = kNameSpace_GetCoercionMethodNULL;
	l->kNameSpace_GetMethodByParamSizeNULL  = kNameSpace_GetMethodByParamSizeNULL;
	l->kNameSpace_GetMethodBySignatureNULL  = kNameSpace_GetMethodBySignatureNULL;
	l->kMethod_DoLazyCompilation = kMethod_DoLazyCompilation;
	l->kNameSpace_FreeSugarExtension =  kNameSpace_FreeSugarExtension;
	l->Konoha_LoadScript = Konoha_LoadScript;
	l->Konoha_Eval       = Konoha_Eval;
	l->kMethod_GenCode   = kMethod_GenCode;
	l->kMethod_SetFunc   = kMethod_SetFunc;

	KDEFINE_CLASS defSymbol = {0};
	defSymbol.structname = "Symbol";
	defSymbol.typeId = KTypeAttr_NewId;
	defSymbol.cflag = KClassFlag_int;
	defSymbol.init = KClass_(KType_Int)->init;
	defSymbol.unbox = KClass_(KType_Int)->unbox;
	defSymbol.format = kSymbol_format;

	KDEFINE_CLASS defSyntax = {0};
	SETSTRUCTNAME(defSyntax, Syntax);
	defSyntax.init = kSyntax_Init;
	//defSyntax.format = kSyntax_format;

	KDEFINE_CLASS defToken = {0};
	SETSTRUCTNAME(defToken, Token);
	defToken.init = kToken_Init;
	defToken.reftrace = kToken_Reftrace;
	defToken.format = kToken_format;

	KDEFINE_CLASS defNode = {0};
	SETSTRUCTNAME(defNode, Node);
	defNode.init = kUntypedNode_Init;
	defNode.reftrace = kUntypedNode_Reftrace;
	defNode.format        = kUntypedNode_format;

	InitNodeClass(kctx, mod);

	mod->cSymbol =    KLIB KClass_define(kctx, PackageId_sugar, NULL, &defSymbol, 0);
	mod->cSyntax =    KLIB KClass_define(kctx, PackageId_sugar, NULL, &defSyntax, 0);
	mod->cToken =     KLIB KClass_define(kctx, PackageId_sugar, NULL, &defToken, 0);
	mod->cNode  =     KLIB KClass_define(kctx, PackageId_sugar, NULL, &defNode, 0);
	mod->cTokenArray = KClass_p0(kctx, KClass_Array, mod->cToken->typeId);

	KLIB Knull(kctx, mod->cToken);
	KLIB Knull(kctx, mod->cNode);
	SugarModule_Setup(kctx, &mod->h, 0);

	KDEFINE_INT_CONST ClassData[] = {   // konoha defined class
		{"void", VirtualType_KClass,    (uintptr_t)KClass_void},
		{"boolean", VirtualType_KClass, (uintptr_t)KClass_Boolean},
		{"int",    VirtualType_KClass,  (uintptr_t)KClass_Int},
		{"String", VirtualType_KClass,  (uintptr_t)KClass_String},
		{"Func",   VirtualType_KClass,  (uintptr_t)KClass_Func},
		{"System", VirtualType_KClass,  (uintptr_t)KClass_System},
		{NULL},
	};
	kNameSpace_LoadConstData(kctx, KNULL(NameSpace), KConst_(ClassData), 0);

	l->Tokenize              = Tokenize;
	l->ApplyMacroData        = ApplyMacroData;
	l->SetMacroData          = SetMacroData;
	l->Preprocess            = Preprocess;
	l->EvalTokenList         = EvalTokenList;
	l->ParseTypePattern      = ParseTypePattern;
	l->kToken_ToBraceGroup   = kToken_ToBraceGroup;
	l->kUntypedNode_AddParsedObject = kUntypedNode_AddParsedObject;
	l->FindEndOfStatement    = FindEndOfStatement;
	l->kUntypedNode_ParseFlag       = kUntypedNode_ParseFlag;
	l->kUntypedNode_GetToken        = kUntypedNode_GetToken;
	l->kUntypedNode_GetNode         = kUntypedNode_GetNode;
	l->kUntypedNode_SetConst        = kUntypedNode_SetConst;
	l->kUntypedNode_SetUnboxConst   = kUntypedNode_SetUnboxConst;
	l->kUntypedNode_SetVariable     = kUntypedNode_SetVariable;
	l->TypeCheckNodeAt       = TypeCheckNodeAt;
	l->TypeCheckNodeByName   = TypeCheckNodeByName;
	l->TypeCheckMethodParam  = TypeCheckMethodParam;
	l->new_MethodNode        = new_MethodNode;
	l->AddLocalVariable      = AddLocalVariable;
	l->kUntypedNode_DeclType        = kUntypedNode_DeclType;
	l->TypeVariableNULL      = TypeVariableNULL;

	l->kNameSpace_DefineSyntax = kNameSpace_DefineSyntax;
	l->kNameSpace_GetSyntax    = kNameSpace_GetSyntax;
	l->kSyntax_AddPattern      = kSyntax_AddPattern;
	l->kNameSpace_AddSyntax    = kNameSpace_AddSyntax;
	l->kNameSpace_UseDefaultVirtualMachine = kNameSpace_UseDefaultVirtualMachine;
	l->kUntypedNode_InsertAfter       = kUntypedNode_InsertAfter;
	l->kUntypedNode_AddNode           = kUntypedNode_AddNode;
	l->kUntypedNode_Op                = kUntypedNode_Op;
	l->ParseSyntaxNode         = ParseSyntaxNode;
	l->ParseNode               = ParseNode;
	l->ParseNewNode            = ParseNewNode;
	l->AppendParsedNode        = AppendParsedNode;
	l->kToken_ToError          = kToken_ToError;
	l->MessageNode             = MessageNode;
	l->VisitNode               = VisitNode;

#ifndef USE_SMALLBUILD
	l->dumpToken      = dumpToken;
	l->dumpTokenArray = dumpTokenArray;
#endif

	DefineDefaultSyntax(kctx, KNULL(NameSpace));
}
コード例 #17
0
ファイル: Syntax_glue.c プロジェクト: myoan/minikonoha
static kbool_t Syntax_ExportNameSpace(KonohaContext *kctx, kNameSpace *ns, kNameSpace *exportNS, int option, KTraceInfo *trace)
{
	KDEFINE_INT_CONST IntData[] = {
#define DEFINE_KEYWORD(KW) {#KW, KType_Int, KW}
		DEFINE_KEYWORD(ErrTag),
		DEFINE_KEYWORD(WarnTag),
		DEFINE_KEYWORD(NoticeTag),
		DEFINE_KEYWORD(InfoTag),
		DEFINE_KEYWORD(DebugTag),

		DEFINE_KEYWORD(TypeCheckPolicy_NoCheck),
		DEFINE_KEYWORD(TypeCheckPolicy_AllowVoid),
		DEFINE_KEYWORD(TypeCheckPolicy_Coercion),
		DEFINE_KEYWORD(TypeCheckPolicy_CONST),

		DEFINE_KEYWORD(Precedence_CPPStyleScope),
		DEFINE_KEYWORD(Precedence_CStyleSuffixCall),  /*x(), x[], x.x x->x x++ */
		DEFINE_KEYWORD(Precedence_CStylePrefixOperator),  /*++x, --x, sizeof x &x +x -x !x (T)x  */
	//	DEFINE_KEYWORD(Precedence_CppMember),  /* .x ->x */
		DEFINE_KEYWORD(Precedence_CStyleMUL),  /* x * x, x / x, x % x*/
		DEFINE_KEYWORD(Precedence_CStyleADD),  /* x + x, x - x */
		DEFINE_KEYWORD(Precedence_CStyleSHIFT),  /* x << x, x >> x */
		DEFINE_KEYWORD(Precedence_CStyleCOMPARE),
		DEFINE_KEYWORD(Precedence_CStyleEquals),
		DEFINE_KEYWORD(Precedence_CStyleBITAND),
		DEFINE_KEYWORD(Precedence_CStyleBITXOR),
		DEFINE_KEYWORD(Precedence_CStyleBITOR),
		DEFINE_KEYWORD(Precedence_CStyleAND),
		DEFINE_KEYWORD(Precedence_CStyleOR),
		DEFINE_KEYWORD(Precedence_CStyleTRINARY),  /* ? : */
		DEFINE_KEYWORD(Precedence_CStyleAssign),
		DEFINE_KEYWORD(Precedence_CStyleCOMMA),
		DEFINE_KEYWORD(Precedence_Statement),
		DEFINE_KEYWORD(Precedence_CStyleStatementEnd),

		DEFINE_KEYWORD(KNode_Done),
		DEFINE_KEYWORD(KNode_Const),
		DEFINE_KEYWORD(KNode_New),
		DEFINE_KEYWORD(KNode_Null),
		DEFINE_KEYWORD(KNode_UnboxConst),
		DEFINE_KEYWORD(KNode_Local),
		DEFINE_KEYWORD(KNode_Field),
		DEFINE_KEYWORD(KNode_Box),
		DEFINE_KEYWORD(KNode_MethodCall),
		DEFINE_KEYWORD(KNode_And),
		DEFINE_KEYWORD(KNode_Or),
		DEFINE_KEYWORD(KNode_Assign),
		DEFINE_KEYWORD(KNode_Block),
		DEFINE_KEYWORD(KNode_If),
		DEFINE_KEYWORD(KNode_While),
		DEFINE_KEYWORD(KNode_DoWhile),
		DEFINE_KEYWORD(KNode_Return),
		DEFINE_KEYWORD(KNode_Break),
		DEFINE_KEYWORD(KNode_Continue),
		DEFINE_KEYWORD(KNode_Try),
		DEFINE_KEYWORD(KNode_Throw),
		DEFINE_KEYWORD(KNode_Error),

#undef DEFINE_KEYWORD
		{NULL},
	};
	KLIB kNameSpace_LoadConstData(kctx, exportNS, KConst_(IntData), trace);
	return true;
}
コード例 #18
0
ファイル: parser.c プロジェクト: kkuramitsu/minikonoha
void MODSUGAR_Init(KonohaContext *kctx, KonohaContextVar *ctx)
{
	KModuleSugar *mod = (KModuleSugar *)KCalloc_UNTRACE(sizeof(KModuleSugar), 1);
	mod->h.name     = "sugar";
	mod->h.allocSize = sizeof(KModuleSugar);
	mod->h.setupModuleContext    = SugarModule_Setup;
	KLIB KonohaRuntime_setModule(kctx, MOD_sugar, (KonohaModule *)mod, 0);

	KonohaLibVar* l = (KonohaLibVar *)ctx->klib;
	l->kNameSpace_GetClass       = kNameSpace_GetClass;
	l->kNameSpace_DefineClass    = kNameSpace_DefineClass;
	l->kNameSpace_LoadMethodData = kNameSpace_LoadMethodData;
	l->kNameSpace_SetConstData   = kNameSpace_SetConstData;
	l->kNameSpace_LoadConstData  = kNameSpace_LoadConstData;
	l->kNameSpace_GetGetterMethodNULL  = kNameSpace_GetGetterMethodNULL;
	l->kNameSpace_GetSetterMethodNULL  = kNameSpace_GetSetterMethodNULL;
	l->kNameSpace_GetCoercionMethodNULL = kNameSpace_GetCoercionMethodNULL;
	l->kNameSpace_GetMethodByParamSizeNULL  = kNameSpace_GetMethodByParamSizeNULL;
	l->kNameSpace_GetMethodBySignatureNULL  = kNameSpace_GetMethodBySignatureNULL;
	l->kMethod_DoLazyCompilation = kMethod_DoLazyCompilation;
//	l->kNameSpace_compileAllDefinedMethods  = kNameSpace_compileAllDefinedMethods;
	l->kNameSpace_FreeSugarExtension =  kNameSpace_FreeSugarExtension;
	l->Konoha_LoadScript = Konoha_LoadScript;
	l->Konoha_Eval       = Konoha_Eval;
	l->kMethod_GenCode   = kMethod_GenCode;
	l->kMethod_setFunc   = kMethod_setFunc;

	KDEFINE_CLASS defToken = {0};
	SETSTRUCTNAME(defToken, Token);
	defToken.init = kToken_Init;
	defToken.reftrace = kToken_Reftrace;
	defToken.p = kToken_p;
	
	KDEFINE_CLASS defExpr = {0};
	SETSTRUCTNAME(defExpr, Expr);
	defExpr.init = kExpr_Init;
	defExpr.reftrace = kExpr_Reftrace;
	defExpr.p        = kExpr_p;
	
	KDEFINE_CLASS defStmt = {0};
	SETSTRUCTNAME(defStmt, Stmt);
	defStmt.init = kStmt_Init;
	defStmt.reftrace = kStmt_Reftrace;
	defStmt.p        = kStmt_p;
	
	KDEFINE_CLASS defBlock = {0};
	SETSTRUCTNAME(defBlock, Block);
	defBlock.init = kBlock_Init;
	defBlock.reftrace = kBlock_Reftrace;
	
	KDEFINE_CLASS defGamma = {0};
	SETSTRUCTNAME(defGamma, Gamma);
	defGamma.init = Gamma_Init;

	mod->cToken =     KLIB KonohaClass_define(kctx, PackageId_sugar, NULL, &defToken, 0);
	mod->cExpr  =     KLIB KonohaClass_define(kctx, PackageId_sugar, NULL, &defExpr, 0);
	mod->cStmt  =     KLIB KonohaClass_define(kctx, PackageId_sugar, NULL, &defStmt, 0);
	mod->cBlock =     KLIB KonohaClass_define(kctx, PackageId_sugar, NULL, &defBlock, 0);
	mod->cGamma =     KLIB KonohaClass_define(kctx, PackageId_sugar, NULL, &defGamma, 0);
	mod->cTokenArray = CT_p0(kctx, CT_Array, mod->cToken->typeId);

	KLIB Knull(kctx, mod->cToken);
	KLIB Knull(kctx, mod->cExpr);
	kStmtVar *NullStmt = (kStmtVar *)KLIB Knull(kctx, mod->cStmt);
	KFieldSet(NullStmt, NullStmt->parentBlockNULL, (kBlock *)KLIB Knull(kctx, mod->cBlock));

	SugarModule_Setup(kctx, &mod->h, 0);

	KDEFINE_INT_CONST ClassData[] = {   // minikonoha defined class
		{"void", VirtualType_KonohaClass, (uintptr_t)CT_void},
		{"boolean", VirtualType_KonohaClass, (uintptr_t)CT_Boolean},
		{"int",    VirtualType_KonohaClass, (uintptr_t)CT_Int},
		{"String", VirtualType_KonohaClass, (uintptr_t)CT_String},
		{"Func",   VirtualType_KonohaClass, (uintptr_t)CT_Func},
		{"System", VirtualType_KonohaClass, (uintptr_t)CT_System},
		{NULL},
	};
	kNameSpace_LoadConstData(kctx, KNULL(NameSpace), KonohaConst_(ClassData), 0);

	mod->kNameSpace_SetTokenFunc       = kNameSpace_SetTokenFunc;
	mod->TokenSeq_Tokenize        = TokenSeq_Tokenize;
	mod->TokenSeq_ApplyMacro      = TokenSeq_ApplyMacro;
	mod->kNameSpace_SetMacroData       = kNameSpace_SetMacroData;
	mod->TokenSeq_Resolve        = TokenSeq_Resolve;
	mod->TokenSeq_Eval            = TokenSeq_Eval;
	mod->TokenUtils_ParseTypePattern     = TokenUtils_ParseTypePattern;
	mod->kToken_ToBraceGroup = kToken_ToBraceGroup;
	mod->kStmt_AddParsedObject      = kStmt_AddParsedObject;
	mod->kNameSpace_FindEndOfStatement = kNameSpace_FindEndOfStatement;
	mod->kStmt_ParseFlag            = kStmt_ParseFlag;
	mod->kStmt_GetToken             = kStmt_GetToken;
	mod->kStmt_GetBlock             = kStmt_GetBlock;
	mod->kStmt_GetExpr              = kStmt_GetExpr;
	mod->kStmt_GetText              = kStmt_GetText;
	mod->kExpr_SetConstValue        = kExpr_SetConstValue;
	mod->kExpr_SetUnboxConstValue   = kExpr_SetUnboxConstValue;
	mod->kExpr_SetVariable          = kExpr_SetVariable;
	mod->kStmt_TypeCheckExprAt        = kStmt_TypeCheckExprAt;
	mod->kStmt_TypeCheckByName        = kStmt_TypeCheckByName;
	mod->kBlock_TypeCheckAll          = kBlock_TypeCheckAll;
	mod->kStmtkExpr_TypeCheckCallParam = kStmtkExpr_TypeCheckCallParam;
	mod->new_TypedCallExpr          = new_TypedCallExpr;
	mod->kGamma_AddLocalVariable = kGamma_AddLocalVariable;
	mod->kStmt_DeclType             = kStmt_DeclType;
	mod->kStmt_TypeCheckVariableNULL  = kStmt_TypeCheckVariableNULL;

	mod->kNameSpace_DefineSyntax    = kNameSpace_DefineSyntax;
	mod->kNameSpace_GetSyntax       = kNameSpace_GetSyntax;
	mod->kArray_AddSyntaxRule       = kArray_AddSyntaxPattern;
//	mod->kNameSpace_SetSugarFunc    = kNameSpace_SetSugarFunc;
	mod->kNameSpace_AddSugarFunc    = kNameSpace_AddSugarFunc;
	mod->new_kBlock                 = new_kBlock;
	mod->new_kStmt                  = new_kStmt;
	mod->kBlock_InsertAfter         = kBlock_InsertAfter;
	mod->new_UntypedTermExpr        = new_UntypedTermExpr;
	mod->new_UntypedCallStyleExpr   = new_UntypedCallStyleExpr;
	mod->kStmt_ParseOperatorExpr    = kStmt_ParseOperatorExpr;
	mod->kStmt_ParseExpr            = kStmt_ParseExpr;
	mod->kStmt_AddExprParam         = kStmt_AddExprParam;
	mod->kStmt_RightJoinExpr        = kStmt_RightJoinExpr;
	mod->kToken_ToError        = kToken_ToError;
	mod->kStmt_Message2        = kStmt_Message2;

	mod->VisitStmt                  = VisitStmt;
	mod->VisitExpr                  = VisitExpr;
	mod->VisitBlock                 = VisitBlock;

#ifndef USE_SMALLBUILD
	mod->dumpToken      = dumpToken;
	mod->dumpTokenArray = dumpTokenArray;
	mod->dumpExpr       = dumpExpr;
#endif

	DefineDefaultSyntax(kctx, KNULL(NameSpace));
}
コード例 #19
0
ファイル: Libevent_glue.c プロジェクト: wakamori/aspen
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;
}
コード例 #20
0
ファイル: sugar_glue.c プロジェクト: kkuramitsu/minikonoha
static kbool_t sugar_PackupNameSpace(KonohaContext *kctx, kNameSpace *ns, int option, KTraceInfo *trace)
{
	KonohaClass *cSymbol = defineSymbolClass(kctx, ns, trace);
	KonohaClass *ccid = loadcidClass(kctx, ns, trace);
	KDEFINE_INT_CONST ClassData[] = {   // add Array as available
		{"Token", VirtualType_KonohaClass, (uintptr_t)CT_Token},
		{"Stmt", VirtualType_KonohaClass,  (uintptr_t)CT_Stmt},
		{"Expr", VirtualType_KonohaClass,  (uintptr_t)CT_Expr},
		{"Block", VirtualType_KonohaClass, (uintptr_t)CT_Block},
		{"Gamma", VirtualType_KonohaClass, (uintptr_t)CT_Gamma},
		{"NameSpace", VirtualType_KonohaClass, (uintptr_t)CT_NameSpace},
		{"symbol", VirtualType_KonohaClass, (uintptr_t)cSymbol},
		{NULL},
	};
	KLIB kNameSpace_LoadConstData(kctx, ns, KonohaConst_(ClassData), 0);

	int TY_Symbol = cSymbol->typeId;
	sugar_defineTokenFunc(kctx, ns, TY_Symbol, trace);
	sugar_defineMessageMethod(kctx, ns, TY_Symbol, trace);


	int FN_buildid = FN_("buildid"), FN_key = FN_("key"), FN_defval = FN_("defval");
	int FN_typeid = FN_("typeid"), FN_gma = FN_("gma"), FN_pol = FN_("pol");
	int FN_msg = FN_("msg");
	int FN_x = FN_("x");
	int FN_tokenList = FN_("tokens"), FN_s = FN_("s"), FN_e = FN_("e");
	int FN_expr = FN_("expr");

	/* Array[String] */
	kparamtype_t P_StringArray[] = {{TY_String}};
	int TY_StringArray = (KLIB KonohaClass_Generics(kctx, CT_Array, TY_void, 1, P_StringArray))->typeId;

	ktype_t TY_symbol = cSymbol->typeId;
	ktype_t TY_cid = ccid->typeId;

	KDEFINE_METHOD MethodData[] = {
		/* Token */
		_Public, _F(Token_new), TY_Token, TY_Token, MN_("new"), 1, TY_symbol, FN_key,
		_Public, _F(Token_setUnresolvedTokenType),  TY_void, TY_Token, MN_("setUnresolvedTokenType"),  1, TY_symbol, FN_x,
		_Public, _F(Token_setText),  TY_void, TY_Token, MN_("setText"),  1, TY_String, FN_x,
		_Public, _F(Token_setSubArray), TY_void, TY_Token, MN_("setSubArray"), 1, TY_StringArray, FN_x,
//		_Public, _F(Token_isTypeName), TY_boolean, TY_Token, MN_("isTypeName"), 0,
		_Public, _F(Token_isParenthesis), TY_boolean, TY_Token, MN_("isParenthesis"), 0,
		_Public, _F(Token_getText), TY_String, TY_Token, MN_("getText"), 0,
		_Public, _F(Token_isSymbol), TY_boolean, TY_Token, MN_("isSymbol"), 0,
		_Public, _F(Token_newUntypedExpr), TY_Expr, TY_Token, MN_("newUntypedExpr"), 0,
		_Public, _F(Token_isBeforeWhiteSpace), TY_boolean, TY_Token, MN_("isBeforeWhiteSpace"), 0,

		/* Stmt */
		_Public, _F(Stmt_getBuild), TY_int, TY_Stmt,  MN_("getBuild"), 0,
		_Public, _F(Stmt_setBuild), TY_void, TY_Stmt, MN_("setBuild"), 1, TY_int, FN_buildid,
		_Public, _F(Stmt_getBlock), TY_Block, TY_Stmt, MN_("getBlock"), 2, TY_symbol, FN_key, TY_Block, FN_defval,
		_Public, _F(Stmt_getToken), TY_Token, TY_Stmt, MN_("getToken"), 2, TY_symbol, FN_key, TY_Token, FN_defval,
		_Public, _F(Stmt_getExpr), TY_Expr, TY_Stmt, MN_("getExpr"), 2, TY_symbol, FN_key, TY_Expr, FN_defval,
		_Public, _F(Stmt_TypeCheckExpr), TY_boolean, TY_Stmt, MN_("TypeCheckExpr"), 3, TY_symbol, FN_key, TY_Gamma, FN_gma, TY_cid, FN_typeid,
		_Public, _F(Stmt_TypeCheckExprPol), TY_boolean, TY_Stmt, MN_("TypeCheckExpr"), 4, TY_symbol, FN_key, TY_Gamma, FN_gma, TY_cid, FN_typeid, TY_int, FN_pol,
		_Public, _F(Stmt_Message2rintError), TY_Expr, TY_Stmt, MN_("printError"), 1, TY_String, FN_msg,

		_Public, _F(Stmt_newExpr), TY_Expr, TY_Stmt, MN_("newExpr"), 3, TY_TokenArray, FN_tokenList, TY_int, FN_s, TY_int, FN_e,
		_Public, _F(Stmt_setType), TY_void, TY_Stmt, MN_("setType"), 1, TY_int, FN_x,
//		_Public, _F(kStmt_Message2arsedExpr), TY_Expr, TY_Stmt, MN_("parseExpr"), 3, TY_TokenArray, FN_tokenList, TY_int, FN_s, TY_int, FN_e,
		_Public, _F(Stmt_newUntypedCallStyleExpr2), TY_Expr, TY_Stmt, MN_("newUntypedCallStyleExpr"), 2, TY_Token, FN_("token"), TY_Expr, FN_("expr1"),
		_Public, _F(Stmt_newUntypedCallStyleExpr3), TY_Expr, TY_Stmt, MN_("newUntypedCallStyleExpr"), 3, TY_Token, FN_("token"), TY_Expr, FN_("expr1"), TY_Expr, FN_("expr2"),
		_Public, _F(Stmt_newUntypedCallStyleExpr4), TY_Expr, TY_Stmt, MN_("newUntypedCallStyleExpr"), 4, TY_Token, FN_("token"), TY_Expr, FN_("expr1"), TY_Expr, FN_("expr2"), TY_Expr, FN_("expr3"),
		_Public, _F(Stmt_newUntypedCallStyleExpr5), TY_Expr, TY_Stmt, MN_("newUntypedCallStyleExpr"), 5, TY_Token, FN_("token"), TY_Expr, FN_("expr1"), TY_Expr, FN_("expr2"), TY_Expr, FN_("expr3"), TY_Expr, FN_("expr4"),
		_Public, _F(Stmt_newUntypedCallStyleExpr6), TY_Expr, TY_Stmt, MN_("newUntypedCallStyleExpr"), 6, TY_Token, FN_("token"), TY_Expr, FN_("expr1"), TY_Expr, FN_("expr2"), TY_Expr, FN_("expr3"), TY_Expr, FN_("expr4"), TY_Expr, FN_("expr5"),
		_Public, _F(Stmt_newTypedCallExpr1), TY_Expr, TY_Stmt, MN_("newTypedCallExpr"), 4, TY_Gamma, FN_gma, TY_cid, FN_typeid, TY_symbol, FN_("methodName"), TY_Expr, FN_("firstExpr"),
		_Public, _F(Stmt_newTypedCallExpr2), TY_Expr, TY_Stmt, MN_("newTypedCallExpr"), 5, TY_Gamma, FN_gma, TY_cid, FN_typeid, TY_symbol, FN_("methodName"), TY_Expr, FN_("firstExpr"), TY_Expr, FN_("secondExpr"),
		_Public, _F(Stmt_rightJoinExpr), TY_Expr, TY_Stmt, MN_("rightJoinExpr"), 4, TY_Expr, FN_expr, TY_TokenArray, FN_tokenList, TY_int, FN_s, TY_int, FN_e,
		_Public, _F(Stmt_getTokenList), TY_TokenArray, TY_Stmt, MN_("getTokenList"), 2, TY_symbol, FN_key, TY_TokenArray, FN_defval,
		_Public, _F(Stmt_done), TY_void, TY_Stmt, MN_("done"), 0,
		_Public, _F(Stmt_setObject), TY_void, TY_Stmt, MN_("setExpr"), 2, TY_symbol, FN_key, TY_Expr, FN_expr,
		_Public, _F(Stmt_setObject), TY_void, TY_Stmt, MN_("setBlock"), 2, TY_symbol, FN_key, TY_Block, FN_("block"),
		_Public, _F(Stmt_declType), TY_boolean, TY_Stmt, MN_("declType"), 3, TY_Gamma, FN_gma, TY_cid, FN_typeid, TY_Expr, FN_("declExpr"),
		_Public, _F(Stmt_newBlock), TY_Block, TY_Stmt, MN_("newBlock"), 1, TY_String, FN_("macro"),

		/* Expr */
		_Public, _F(Expr_getTermToken), TY_Token, TY_Expr, MN_("getTermToken"), 0,
		_Public, _F(Expr_setConstValue), TY_Expr, TY_Expr, MN_("setConstValue"), 1, TY_Object, FN_("value") | FN_COERCION,
		_Public, _F(Expr_setVariable), TY_Expr, TY_Expr, MN_("setVariable"), 4, TY_Gamma, FN_gma, TY_int, FN_buildid, TY_cid, FN_typeid, TY_int, FN_("index"),
		_Public, _F(Expr_newVariableExpr), TY_Expr, TY_Expr, MN_("new"), 4, TY_Gamma, FN_gma, TY_int, FN_buildid, TY_cid, FN_typeid, TY_int, FN_("index"),
		_Public, _F(Expr_new), TY_Expr, TY_Expr, MN_("new"), 1, TY_Object, FN_("value") | FN_COERCION,
		_Public, _F(Expr_setType), TY_void, TY_Expr, MN_("setType"), 2, TY_int, FN_buildid, TY_cid, FN_typeid,
		_Public, _F(kExpr_AddExpr), TY_Expr, TY_Expr, MN_("addExpr"), 1, TY_Expr, FN_expr,

		/* Block */
		_Public, _F(Block_TypeCheckAll), TY_boolean, TY_Block, MN_("TypeCheckAll"), 1, TY_Gamma, FN_gma,

		/* Gamma */
		_Public, _F(Gamma_declareLocalVariable), TY_int, TY_Gamma, MN_("declareLocalVariable"), 2, TY_cid, FN_typeid, TY_symbol, FN_key,
		DEND,
	};
	KLIB kNameSpace_LoadMethodData(kctx, ns, MethodData, trace);
	LoadNameSpaceMethodData(kctx, ns, TY_symbol, trace);
	RENAMEME_InitNameSpace(kctx, ns, ns, trace);
	return true;
}
コード例 #21
0
ファイル: Math_glue.c プロジェクト: imasahiro/konoha3
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;
}
コード例 #22
0
ファイル: Curl_glue.c プロジェクト: imasahiro/konoha3
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;
}
コード例 #23
0
ファイル: xml_glue.c プロジェクト: Kouhei-Moriya/konoha3
static kbool_t xml_PackupNameSpace(KonohaContext *kctx, kNameSpace *ns, int option, KTraceInfo *trace)
{
	KRequireKonohaCommonModel(trace);
	KDEFINE_CLASS defXml = {
		STRUCTNAME(XmlReader),
		.cflag = KClassFlag_Final,
		.init = XmlReader_init,
		.free = XmlReader_free,
		.reftrace = XmlReader_reftrace,
	};
	KClass *cXmlReader = KLIB kNameSpace_DefineClass(kctx, ns, NULL, &defXml, trace);
#define KType_XmlReader     cXmlReader->typeId


	KDEFINE_METHOD MethodData[] = {
		_Public, _F(XmlReader_new),                  KType_XmlReader,     KType_XmlReader,    KMethodName_("new"),                  1, KType_String, KFieldName_("path"),
		_Public, _F(XmlReader_close),                KType_void,    KType_XmlReader,    KMethodName_("close"),                0,
		_Public, _F(XmlReader_getQuoteChar),         KType_String,  KType_XmlReader,    KMethodName_("getQuoteChar"),         0,
		_Public, _F(XmlReader_read),                 KType_Boolean, KType_XmlReader,    KMethodName_("read"),                 0,
		_Public, _F(XmlReader_readState),            KType_Int,     KType_XmlReader,    KMethodName_("readState"),            0,
		_Public, _F(XmlReader_nodeType),             KType_Int,     KType_XmlReader,    KMethodName_("nodeType"),             0,
		_Public, _F(XmlReader_isNamespaceDecl),      KType_Boolean, KType_XmlReader,    KMethodName_("isNamespaceDecl"),      0,
		_Public, _F(XmlReader_isEmptyElement),       KType_Boolean, KType_XmlReader,    KMethodName_("isEmptyElement"),       0,
		_Public, _F(XmlReader_hasAttributes),        KType_Boolean, KType_XmlReader,    KMethodName_("hasAttributes"),        0,
		_Public, _F(XmlReader_hasValue),             KType_Boolean, KType_XmlReader,    KMethodName_("hasValue"),             0,
		_Public, _F(XmlReader_getDepth),             KType_Int,     KType_XmlReader,    KMethodName_("getDepth"),             0,
		_Public, _F(XmlReader_getAttributeCount),    KType_Int,     KType_XmlReader,    KMethodName_("getAttributeCount"),    0,
		_Public, _F(XmlReader_moveToFirstAttribute), KType_Boolean, KType_XmlReader,    KMethodName_("moveToFirstAttribute"), 0,
		_Public, _F(XmlReader_moveToNextAttribute),  KType_Boolean, KType_XmlReader,    KMethodName_("moveToNextAttribute"),  0,
		_Public, _F(XmlReader_moveToElement),        KType_Boolean, KType_XmlReader,    KMethodName_("moveToElement"),        0,
		_Public, _F(XmlReader_constBaseUri),         KType_String,  KType_XmlReader,    KMethodName_("constBaseUri"),         0,
		_Public, _F(XmlReader_constEncoding),        KType_String,  KType_XmlReader,    KMethodName_("constEncoding"),        0,
		_Public, _F(XmlReader_constValue),           KType_String,  KType_XmlReader,    KMethodName_("constValue"),           0,
		_Public, _F(XmlReader_constNamespaceUri),    KType_String,  KType_XmlReader,    KMethodName_("constNamespaceUri"),    0,
		_Public, _F(XmlReader_constLocalName),       KType_String,  KType_XmlReader,    KMethodName_("constLocalName"),       0,
		_Public, _F(XmlReader_constName),            KType_String,  KType_XmlReader,    KMethodName_("constName"),            0,
		_Public, _F(XmlReader_constXmlLang),         KType_String,  KType_XmlReader,    KMethodName_("constXmlLang"),         0,
		_Public, _F(XmlReader_constPrefix),          KType_String,  KType_XmlReader,    KMethodName_("constPrefix"),          0,
		_Public, _F(XmlReader_getAttribute),         KType_String,  KType_XmlReader,    KMethodName_("getAttribute"),         0,
		_Public, _F(XmlReader_getAttributeNo),       KType_String,  KType_XmlReader,    KMethodName_("getAttributeNo"),       1, KType_Int, KFieldName_("no"),
		_Public, _F(XmlReader_getAttributeNs),       KType_String,  KType_XmlReader,    KMethodName_("getAttributeNs"),       2, KType_String, KFieldName_("ns"), KType_String, KFieldName_("name"),
		_Public, _F(XmlReader_lookupNameSpace),      KType_String,  KType_XmlReader,    KMethodName_("lookupNameSpace"),      1, KType_String, KFieldName_("ns"),
		_Public, _F(XmlReader_normalization),        KType_Int,     KType_XmlReader,    KMethodName_("normalization"),        0,

		_Public, _F(String_convertToXml),            KType_XmlReader,     KType_String, KMethodName_("convertToXml"),         0,
		DEND,
	};
	KLIB kNameSpace_LoadMethodData(kctx, ns, MethodData, trace);
	KDEFINE_INT_CONST IntData[] = {
		{KDefineConstInt(XML_READER_TYPE_NONE)},
		{KDefineConstInt(XML_READER_TYPE_ELEMENT)},
		{KDefineConstInt(XML_READER_TYPE_ATTRIBUTE)},
		{KDefineConstInt(XML_READER_TYPE_TEXT)},
		{KDefineConstInt(XML_READER_TYPE_CDATA)},
		{KDefineConstInt(XML_READER_TYPE_ENTITY_REFERENCE)},
		{KDefineConstInt(XML_READER_TYPE_ENTITY)},
		{KDefineConstInt(XML_READER_TYPE_PROCESSING_INSTRUCTION)},
		{KDefineConstInt(XML_READER_TYPE_COMMENT)},
		{KDefineConstInt(XML_READER_TYPE_DOCUMENT)},
		{KDefineConstInt(XML_READER_TYPE_DOCUMENT_TYPE)},
		{KDefineConstInt(XML_READER_TYPE_DOCUMENT_FRAGMENT)},
		{KDefineConstInt(XML_READER_TYPE_NOTATION)},
		{KDefineConstInt(XML_READER_TYPE_WHITESPACE)},
		{KDefineConstInt(XML_READER_TYPE_SIGNIFICANT_WHITESPACE)},
		{KDefineConstInt(XML_READER_TYPE_END_ELEMENT)},
		{KDefineConstInt(XML_READER_TYPE_END_ENTITY)},
		{KDefineConstInt(XML_READER_TYPE_XML_DECLARATION)},
		{} // end of const data
	};
	KLIB kNameSpace_LoadConstData(kctx, ns, KConst_(IntData), trace);
	return true;
}