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; }
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; }
static kbool_t exception_initPackage(KonohaContext *kctx, kNameSpace *ns, int argc, const char**args, kfileline_t pline) { KonohaExceptionModule *mod = (KonohaExceptionModule*)KCALLOC(sizeof(KonohaExceptionModule), 1); mod->h.name = "exception"; mod->h.setup = kModuleException_setup; mod->h.reftrace = kModuleException_reftrace; mod->h.free = kModuleException_free; KLIB Konoha_setModule(kctx, MOD_exception, &mod->h, pline); KDEFINE_CLASS defException = { STRUCTNAME(Exception), .cflag = CFLAG_Exception, .init = Exception_init, .reftrace = Exception_reftrace, .p = Exception_p, }; mod->cException = KLIB Konoha_defineClass(kctx, ns->packageId, PN_konoha, NULL, &defException, pline); KDEFINE_METHOD MethodData[] = { _Public|_Hidden, _F(System_throw), TY_void, TY_System, MN_("throw"), 1, TY_Exception, FN_("e"), _Public|_Hidden, _F(System_getThrownException), TY_Exception, TY_System, MN_("getThrownException"), 0, DEND, }; KLIB kNameSpace_loadMethodData(kctx, ns, MethodData); return true; }
static void sugar_defineTokenFunc(KonohaContext *kctx, kNameSpace *ns, int TY_Symbol, KTraceInfo *trace) { KDEFINE_METHOD MethodData[] = { _Public, _F(String_AsciiAt), TY_int, TY_String, MN_("AsciiAt"), 1, TP_pos, _Public, _F(Token_Parse), TY_int, TY_Token, MN_("parse"), 4, TP_kw, TP_source, TP_begin, TP_end, _Public, _F(Token_error), TY_int, TY_Token, MN_("error"), 4, TP_message, TP_source, TP_begin, TP_end, DEND, }; KLIB kNameSpace_LoadMethodData(kctx, ns, MethodData, trace); }
static void sugar_defineMessageMethod(KonohaContext *kctx, kNameSpace *ns, int TY_Symbol, KTraceInfo *trace) { KDEFINE_METHOD MethodData[] = { _Public, _F(Stmt_Message), TY_Expr, TY_Stmt, MN_("message"), 2, TP_level, TP_message, _Public, _F(StmtToken_Message), TY_Expr, TY_Stmt, MN_("message"), 3, TP_level, TP_token, TP_message, _Public, _F(StmtExpr_Message), TY_Expr, TY_Stmt, MN_("message"), 3, TP_level, TP_expr, TP_message, DEND, }; KLIB kNameSpace_LoadMethodData(kctx, ns, MethodData, trace); }
static void object_defineMethod(KonohaContext *kctx, kNameSpace *ns, KTraceInfo *trace) { KDEFINE_METHOD MethodData[] = { _Public|_Im|_Const|_Final, _F(Object_getTypeId), TY_int, TY_Object, MN_("getTypeId"), 0, _Public|_Hidden|_Im|_Const, _F(Object_instanceOf), TY_boolean, TY_Object, MN_("<:"), 1, TY_Object, FN_("type"), _Public|_Hidden|_Im|_Const|kMethod_SmartReturn, _F(Object_as), TY_Object, TY_Object, MN_("as"), 0, DEND, }; KLIB kNameSpace_LoadMethodData(kctx, ns, MethodData, trace); }
static void class_defineMethod(KonohaContext *kctx, kNameSpace *ns, KTraceInfo *trace) { KDEFINE_METHOD MethodData[] = { _Public|_Const|_Ignored, _F(NameSpace_AllowImplicitField), TY_void, TY_NameSpace, MN_("AllowImplicitField"), 1, TY_boolean, FN_("allow"), DEND, }; KLIB kNameSpace_LoadMethodData(kctx, ns, MethodData, trace); }
static kbool_t i_PackupNameSpace(KonohaContext *kctx, kNameSpace *ns, int option, KTraceInfo *trace) { KDEFINE_METHOD MethodData[] = { _Public, _F(NameSpace_man), TY_void, TY_NameSpace, MN_("man"), 1, TY_Object, FN_("x") | FN_COERCION, DEND, }; KLIB kNameSpace_LoadMethodData(kctx, ns, MethodData, trace); return true; }
static kbool_t global_defineMethod(KonohaContext *kctx, kNameSpace *ns, KTraceInfo *trace) { KDEFINE_METHOD MethodData[] = { _Public, _F(NameSpace_AllowImplicitGlobalVariable_), TY_void, TY_NameSpace, MN_("AllowImplicitGlobalVariable"), 1, TY_boolean, FN_("enabled"), DEND, }; KLIB kNameSpace_LoadMethodData(kctx, ns, MethodData, trace); return true; }
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); }
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; }
static kbool_t object_initPackage(KonohaContext *kctx, kNameSpace *ns, int argc, const char**args, 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), 0); KDEFINE_METHOD MethodData[] = { _Public|_Const, _F(Object_getTypeId), TY_int, TY_Object, MN_("getTypeId"), 0, DEND, }; KLIB kNameSpace_loadMethodData(kctx, ns, MethodData); return true; }
static int konoha_handler(request_rec *r) { //konoha_config_t *conf = ap_get_module_config( // r->server->module_config, &konoha_module); if(strcmp(r->handler, "konoha-script")) { return DECLINED; } // if(r->method_number != M_GET) { // TODO // return HTTP_METHOD_NOT_ALLOWED; // } KonohaClass *cRequest; verbose_debug = 1; KonohaContext* konoha = konoha_create(&cRequest); //assert(cRequest != NULL); r->content_encoding = "utf-8"; ap_log_rerror(APLOG_MARK, APLOG_CRIT, 0, r, "filename=%s", r->filename); if(Konoha_LoadScript(konoha, r->filename)) { return DECLINED; } KonohaContext *kctx = konoha; kNameSpace *ns = KNULL(NameSpace); kMethod *mtd = KLIB kNameSpace_GetMethodByParamSizeNULL(kctx, ns, TY_System, MN_("handler"), -1); // fixme if(mtd == NULL) { ap_log_rerror(APLOG_MARK, APLOG_CRIT, 0, r, "System.handler() not found"); return -1; } /* XXX: We assume Request Object may not be freed by GC */ kObject *req_obj = KLIB new_kObject(kctx, OnStack, cRequest, (uintptr_t)r); BEGIN_LOCAL(lsfp, K_CALLDELTA + 1); KUnsafeFieldSet(lsfp[K_CALLDELTA+0].asObject, K_NULL); KUnsafeFieldSet(lsfp[K_CALLDELTA+1].asObject, req_obj); { KonohaStack *sfp = lsfp + K_CALLDELTA; KSetMethodCallStack(sfp, 0/*UL*/, mtd, 1, KLIB Knull(kctx, CT_Int)); KonohaRuntime_callMethod(kctx, sfp); } END_LOCAL(); int ret = lsfp[0].intValue; Konoha_Destroy(konoha); return ret; }
static KMETHOD TypeCheck_as(KonohaContext *kctx, KonohaStack *sfp) { VAR_TypeCheck(stmt, expr, gma, reqty); kExpr *targetExpr = SUGAR kStmt_TypeCheckExprAt(kctx, stmt, expr, 2, gma, TY_var, 0); kExpr *selfExpr = SUGAR kStmt_TypeCheckExprAt(kctx, stmt, expr, 1, gma, targetExpr->ty, TypeCheckPolicy_NOCHECK); if(selfExpr != K_NULLEXPR && targetExpr != K_NULLEXPR) { KonohaClass *selfClass = CT_(selfExpr->ty), *targetClass = CT_(targetExpr->ty); if(selfExpr->ty == targetExpr->ty || selfClass->isSubType(kctx, selfClass, targetClass)) { KReturn(selfExpr); } if(selfClass->isSubType(kctx, targetClass, selfClass)) { kNameSpace *ns = Stmt_ns(stmt); kMethod *mtd = KLIB kNameSpace_GetMethodByParamSizeNULL(kctx, ns, TY_Object, MN_("as"), 0); DBG_ASSERT(mtd != NULL); KReturn(SUGAR kStmtkExpr_TypeCheckCallParam(kctx, stmt, expr, mtd, gma, targetClass->typeId)); } KReturn(kStmtExpr_Message(kctx, stmt, selfExpr, ErrTag, "unable to downcast: %s as %s", TY_t(selfExpr->ty), TY_t(targetExpr->ty))); } }
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; }
static KMETHOD TypeCheck_InstanceOf(KonohaContext *kctx, KonohaStack *sfp) { VAR_TypeCheck(stmt, expr, gma, reqty); kExpr *selfExpr = SUGAR kStmt_TypeCheckExprAt(kctx, stmt, expr, 1, gma, TY_var, 0); kExpr *targetExpr = SUGAR kStmt_TypeCheckExprAt(kctx, stmt, expr, 2, gma, TY_var, 0); if(selfExpr != K_NULLEXPR && targetExpr != K_NULLEXPR) { KonohaClass *selfClass = CT_(selfExpr->ty), *targetClass = CT_(targetExpr->ty); if(CT_is(Final, selfClass)) { kbool_t staticSubType = (selfClass == targetClass || selfClass->isSubType(kctx, selfClass, targetClass)); KReturn(SUGAR kExpr_SetUnboxConstValue(kctx, expr, TY_boolean, staticSubType)); } kNameSpace *ns = Stmt_ns(stmt); kMethod *mtd = KLIB kNameSpace_GetMethodByParamSizeNULL(kctx, ns, TY_Object, MN_("<:"), 1); DBG_ASSERT(mtd != NULL); KFieldSet(expr->cons, expr->cons->MethodItems[0], mtd); kExpr *classValue = SUGAR kExpr_SetConstValue(kctx, expr->cons->ExprItems[2], targetExpr->ty, KLIB Knull(kctx, targetClass)); KFieldSet(expr->cons, expr->cons->ExprItems[2], classValue); KReturn(SUGAR kStmtkExpr_TypeCheckCallParam(kctx, stmt, expr, mtd, gma, TY_boolean)); } }
static KMETHOD TypeCheck_to(KonohaContext *kctx, KonohaStack *sfp) { VAR_TypeCheck(stmt, expr, gma, reqty); kExpr *targetExpr = SUGAR kStmt_TypeCheckExprAt(kctx, stmt, expr, 2, gma, TY_var, 0); kExpr *selfExpr = SUGAR kStmt_TypeCheckExprAt(kctx, stmt, expr, 1, gma, targetExpr->ty, TypeCheckPolicy_NOCHECK); if(selfExpr != K_NULLEXPR && targetExpr != K_NULLEXPR) { KonohaClass *selfClass = CT_(selfExpr->ty), *targetClass = CT_(targetExpr->ty); if(selfExpr->ty == targetExpr->ty || selfClass->isSubType(kctx, selfClass, targetClass)) { kStmtExpr_Message(kctx, stmt, selfExpr, InfoTag, "no need: %s to %s", TY_t(selfExpr->ty), TY_t(targetExpr->ty)); KReturn(selfExpr); } kNameSpace *ns = Stmt_ns(stmt); kMethod *mtd = KLIB kNameSpace_GetCoercionMethodNULL(kctx, ns, selfExpr->ty, targetExpr->ty); if(mtd == NULL) { mtd = KLIB kNameSpace_GetMethodByParamSizeNULL(kctx, ns, selfExpr->ty, MN_("to"), 0); DBG_ASSERT(mtd != NULL); // because Object.to is found. if(mtd->typeId != selfExpr->ty) { KReturn(kStmtExpr_Message(kctx, stmt, selfExpr, ErrTag, "undefined coercion: %s to %s", TY_t(selfExpr->ty), TY_t(targetExpr->ty))); } } KReturn(SUGAR kStmtkExpr_TypeCheckCallParam(kctx, stmt, expr, mtd, gma, targetClass->typeId)); } }
void LoadDefaultSugarMethod(KonohaContext *kctx, kNameSpace *ns) { KSetKLibFunc(0, ReportScriptMessage, TRACE_ReportScriptMessage, NULL); KSetKLibFunc(0, kNameSpace_RequirePackage, kNameSpace_RequirePackage, NULL); KSetKLibFunc(0, kNameSpace_ImportPackage, kNameSpace_ImportPackage, NULL); KSetKLibFunc(0, kNameSpace_ImportPackageSymbol, kNameSpace_ImportPackageSymbol, NULL); KSetKLibFunc(0, kNameSpace_GetConstNULL, kNameSpace_GetConstNULL, NULL); KDEFINE_METHOD MethodData[] = { _Public, _F(NameSpace_ImportPackage), TY_void, TY_NameSpace, MN_("import"), 1, TY_String, FN_("package"), _Public, _F(NameSpace_ImportPackageSymbol), TY_void, TY_NameSpace, MN_("import"), 2, TY_String, FN_("package"), TY_String, FN_("symbol"), _Public, _F(NameSpace_hate), TY_boolean, TY_NameSpace, MN_("hate"), 1, TY_String, FN_("symbol"), _Public, _F(NameSpace_loadScript), TY_void, TY_NameSpace, MN_("load"), 1, TY_String, FN_("filename"), _Public, _F(NameSpace_loadScript), TY_void, TY_NameSpace, MN_("include"), 1, TY_String, FN_("filename"), _Public, _F(NameSpace_useStaticFunc), TY_void, TY_NameSpace, MN_("useStaticFunc"), 1, TY_Object, FN_("class"), DEND, }; KLIB kNameSpace_LoadMethodData(kctx, ns, MethodData, NULL); }
static KMETHOD Statement_import(KonohaContext *kctx, KonohaStack *sfp) { int ret = false; VAR_Statement(stmt, gma); kTokenArray *tokenList = (kTokenArray *) kStmt_GetObjectNULL(kctx, stmt, KW_TokenPattern); if(tokenList == NULL) { KReturnUnboxValue(false); } kNameSpace *ns = Stmt_ns(stmt); SugarSyntaxVar *syn = (SugarSyntaxVar *) SYN_(ns, KW_ExprMethodCall); kExpr *expr; kTokenVar *tkImport = /*G*/new_(TokenVar, 0, OnGcStack); tkImport->resolvedSymbol = MN_("import"); if(IS_Token(tokenList)) { kTokenArray *list = ((kToken *) tokenList)->subTokenList; if(IS_String(list)) { /* case: import cstyle; */ kString *pkgname = (kString *) list; expr = CreateImportCall(kctx, syn, tkImport, ns, pkgname); } else if(kArray_size(list) == 1) { /* case : import("konoha.import"); */ kExpr *param0 = makeStringConstValue(kctx, list->TokenItems[0]->text); expr = SUGAR new_UntypedCallStyleExpr(kctx, syn, 3, tkImport, new_ConstValueExpr(kctx, O_ct(ns), UPCAST(ns)), param0); } else if(kArray_size(list) == 2) { /* case : import("konoha.import", "import"); */ kExpr *param0 = makeStringConstValue(kctx, list->TokenItems[0]->text); kExpr *param1 = makeStringConstValue(kctx, list->TokenItems[1]->text); expr = SUGAR new_UntypedCallStyleExpr(kctx, syn, 4, tkImport, new_ConstValueExpr(kctx, O_ct(ns), UPCAST(ns)), param0, param1); } else { KReturnUnboxValue(false); } } else { KGrowingBuffer wb; KLIB KBuffer_Init(&(kctx->stack->cwb), &wb); /* case : import konoha.import */ ksymbol_t star = SYM_("*"); size_t i = 0; if(i + 2 < kArray_size(tokenList)) { for (; i < kArray_size(tokenList)-1; i+=2) { /* name . */ kToken *tk = tokenList->TokenItems[i+0]; if(i+2 < kArray_size(tokenList)) { kToken *startTk = tokenList->TokenItems[i+2]; if(startTk->resolvedSyntaxInfo->keyword == star) { break; } } KLIB KBuffer_Write(kctx, &wb, S_text(tk->text), S_size(tk->text)); KLIB KBuffer_Write(kctx, &wb, ".", 1); } } kString *name = tokenList->TokenItems[i]->text; KLIB KBuffer_Write(kctx, &wb, S_text(name), S_size(name)); kString *pkgname = KLIB new_kString(kctx, OnGcStack, KLIB KBuffer_Stringfy(kctx, &wb, 1), KBuffer_bytesize(&wb), 0); expr = CreateImportCall(kctx, syn, tkImport, ns, pkgname); } KLIB kObjectProto_SetObject(kctx, stmt, KW_ExprPattern, TY_Expr, expr); ret = SUGAR kStmt_TypeCheckByName(kctx, stmt, KW_ExprPattern, gma, CT_void, TypeCheckPolicy_ALLOWVOID); if(ret) { kStmt_typed(stmt, EXPR); } KReturnUnboxValue(ret); }
static kbool_t regexp_defineMethod(KonohaContext *kctx, kNameSpace *ns, KTraceInfo *trace) { kregexpshare_t *base = (kregexpshare_t *)KCalloc_UNTRACE(sizeof(kregexpshare_t), 1); base->h.name = "regexp"; base->h.setup = kregexpshare_setup; base->h.reftrace = kregexpshare_reftrace; base->h.free = kregexpshare_free; KLIB KonohaRuntime_setModule(kctx, MOD_REGEXP, &base->h, trace); KDEFINE_CLASS RegExpDef = { STRUCTNAME(RegExp), .cflag = 0, .init = RegExp_init, .free = RegExp_free, .p = RegExp_p, }; base->cRegExp = KLIB kNameSpace_defineClass(kctx, ns, NULL, &RegExpDef, trace); ktype_t TY_StringArray0 = CT_StringArray0->typeId; KDEFINE_METHOD MethodData[] = { /*JS*/_Public|_Const|_Im, _F(RegExp_getglobal), TY_boolean, TY_RegExp, MN_("getglobal"), 0, /*JS*/_Public|_Const|_Im, _F(RegExp_getignoreCase), TY_boolean, TY_RegExp, MN_("getignoreCase"), 0, /*JS*/_Public|_Const|_Im, _F(RegExp_getmultiline), TY_boolean, TY_RegExp, MN_("getmultiline"), 0, /*JS*/_Public|_Const|_Im, _F(RegExp_getsource), TY_String, TY_RegExp, MN_("getsource"), 0, /*JS*/_Public|_Const|_Im, _F(RegExp_getlastIndex), TY_int, TY_RegExp, MN_("getlastIndex"), 0, /*JS*/_Public|_Im, _F(String_match), TY_StringArray0, TY_String, MN_("match"), 1, TY_RegExp, FN_("regexp"), /*JS*/_Public|_Const|_Im, _F(String_replace), TY_String, TY_String, MN_("replace"), 2, TY_RegExp, FN_("searchvalue"), TY_String, FN_("newvalue"), /*JS*/_Public|_Const|_Im, _F(String_search), TY_int, TY_String, MN_("search"), 1, TY_RegExp, FN_("searchvalue"), /*JS*/_Public|_Im, _F(String_split), TY_StringArray0, TY_String, MN_("split"), 1, TY_RegExp, FN_("separator"), /*JS*/_Public|_Im, _F(String_splitWithLimit), TY_StringArray0, TY_String, MN_("split"), 2, TY_RegExp, FN_("separator"), TY_int, FN_("limit"), /*JS*/_Public|_Const, _F(RegExp_new), TY_RegExp, TY_RegExp, MN_("new"), 1, TY_String, FN_("pattern"), /*JS*/_Public|_Const, _F(RegExp_new2), TY_RegExp, TY_RegExp, MN_("new"), 2, TY_String, FN_("pattern"), TY_String, FN_("option"), /*JS*/_Public|_Const, _F(RegExp_exec), TY_StringArray0, TY_RegExp, MN_("exec"), 1, TY_String, FN_("str"), /*JS*/_Public|_Const|_Im, _F(RegExp_test), TY_boolean, TY_RegExp, MN_("test"), 1, TY_String, FN_("str"), DEND, }; KLIB kNameSpace_loadMethodData(kctx, ns, MethodData); return true; } static KMETHOD TokenFunc_JavaScriptRegExp(KonohaContext *kctx, KonohaStack *sfp) { kTokenVar *tk = (kTokenVar *)sfp[1].asObject; int ch, prev = '/', pos = 1; const char *source = S_text(sfp[2].asString); if(source[pos] == '*' || source[pos] == '/') { KReturnUnboxValue(0); } /*FIXME: we need to care about context sensitive case*/ //int tokenListize = kArray_size(tenv->tokenList); //if(tokenListize > 0) { // kToken *tkPrev = tenv->tokenList->TokenItems[tokenListize - 1]; // if(tkPrev->unresolvedTokenType == TokenType_INT || // (tkPrev->topCharHint != '(' && tkPrev->unresolvedTokenType == TokenType_SYMBOL)) { // KReturnUnboxValue(0); // } //} while((ch = source[pos++]) != 0) { if(ch == '\n') { break; } if(ch == '/' && prev != '\\') { int pos0 = pos; while(isalpha(source[pos])) pos++; if(IS_NOTNULL(tk)) { kArray *a = (kArray *)KLIB new_kObject(kctx, OnField, CT_StringArray0, 2); // FIXME KFieldSet(tk, tk->subTokenList, a); KLIB new_kString(kctx, a, source + 1, (pos0-2), 0); KLIB new_kString(kctx, a, source + pos0, pos-pos0, 0); tk->unresolvedTokenType = SYM_("$RegExp"); } KReturnUnboxValue(pos); } prev = ch; } if(IS_NOTNULL(tk)) { SUGAR kToken_printMessage(kctx, tk, ErrTag, "must close with %s", "/"); } KReturnUnboxValue(pos-1); }
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, _Public, _F(Thread_equal) , TY_boolean, TY_Thread, MN_("equal"), 1, TY_Thread, FN_x, _Public, _F(Mutex_new) , TY_Mutex, TY_Mutex, MN_("new"), 0, _Public, _F(Mutex_lock) , TY_void, TY_Mutex, MN_("lock"), 0, _Public, _F(Mutex_trylock) , TY_boolean, TY_Mutex, MN_("trylock"), 0, _Public, _F(Mutex_unlock) , TY_void, TY_Mutex, MN_("unlock"), 0, _Public, _F(Cond_new) , TY_Cond, TY_Cond, MN_("new"), 0, _Public, _F(Cond_wait) , TY_void, TY_Cond, MN_("wait"), 1, TY_Mutex, FN_x, _Public, _F(Cond_signal) , TY_void, TY_Cond, MN_("signal"), 0, _Public, _F(Cond_broadcast), TY_void, TY_Cond, MN_("broadcast"), 0, DEND,
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; }
static void LoadNameSpaceMethodData(KonohaContext *kctx, kNameSpace *ns, int TY_symbol, KTraceInfo *trace) { int FN_keyword = SYM_("keyword"); int FN_func = SYM_("func"); /* Func[Int, Token, String] */ kparamtype_t P_FuncTokenize[] = {{TY_Token}, {TY_String}}; int TY_FuncToken = (KLIB KonohaClass_Generics(kctx, CT_Func, TY_int, 2, P_FuncTokenize))->typeId; /* Func[Int, Stmt, Int, Token[], Int, Int] */ kparamtype_t P_FuncPatternMatch[] = {{TY_Stmt}, {TY_int}, {TY_TokenArray}, {TY_int}, {TY_int}}; int TY_FuncPatternMatch = (KLIB KonohaClass_Generics(kctx, CT_Func, TY_int, 5, P_FuncPatternMatch))->typeId; /* Func[Expr, Stmt, Token[], Int, Int, Int] */ kparamtype_t P_FuncExpression[] = {{TY_Stmt}, {TY_TokenArray}, {TY_int}, {TY_int}, {TY_int}}; int TY_FuncExpression = (KLIB KonohaClass_Generics(kctx, CT_Func, TY_Expr, 5, P_FuncExpression))->typeId; /* Func[Boolean, Stmt, Gamma] */ kparamtype_t P_FuncStatement[] = {{TY_Stmt}, {TY_Gamma}}; int TY_FuncStatement = (KLIB KonohaClass_Generics(kctx, CT_Func, TY_boolean, 2, P_FuncStatement))->typeId; /* Func[Expr, Stmt, Expr, Gamma, Int] */ kparamtype_t P_FuncTypeCheck[] = {{TY_Stmt}, {TY_Expr}, {TY_Gamma}, {TY_int}}; int TY_FuncTypeCheck = (KLIB KonohaClass_Generics(kctx, CT_Func, TY_Expr, 4, P_FuncTypeCheck))->typeId; //DBG_P("func=%s", TY_t(TY_FuncTypeCheck)); KDEFINE_METHOD MethodData[] = { _Public|_Im, _F(NameSpace_DefinedSyntax), TY_boolean, TY_NameSpace, MN_("definedSyntax"), 1, TY_symbol, FN_keyword, _Public|_Im, _F(NameSpace_DefinedLiteral), TY_boolean, TY_NameSpace, MN_("definedLiteral"), 1, TY_symbol, FN_keyword, _Public|_Im, _F(NameSpace_DefinedStatement), TY_boolean, TY_NameSpace, MN_("definedStatement"), 1, TY_symbol, FN_keyword, _Public|_Im, _F(NameSpace_DefinedExpression), TY_boolean, TY_NameSpace, MN_("definedExpression"), 1, TY_symbol, FN_keyword, _Public|_Im, _F(NameSpace_DefinedBinaryOperator), TY_boolean, TY_NameSpace, MN_("definedBinaryOperator"), 1, TY_symbol, FN_keyword, // _Public, _F(NameSpace_compileAllDefinedMethods), TY_void, TY_NameSpace, MN_("compileAllDefinedMethods"), 0, _Public, _F(NameSpace_setTokenFunc), TY_void, TY_NameSpace, MN_("setTokenFunc"), 3, TY_symbol, FN_keyword, TY_int, FN_("kchar"), TY_FuncToken, FN_func, _Public, _F(NameSpace_AddPatternMatch), TY_void, TY_NameSpace, MN_("addPatternMatch"), 2, TY_symbol, FN_keyword, TY_FuncPatternMatch, FN_func, _Public, _F(NameSpace_AddExpression), TY_void, TY_NameSpace, MN_("addExpression"), 2, TY_symbol, FN_keyword, TY_FuncExpression, FN_func, _Public, _F(NameSpace_AddTopLevelStatement), TY_void, TY_NameSpace, MN_("addTopLevelStatement"), 2, TY_symbol, FN_keyword, TY_FuncStatement, FN_func, _Public, _F(NameSpace_AddStatement), TY_void, TY_NameSpace, MN_("addStatement"), 2, TY_symbol, FN_keyword, TY_FuncStatement, FN_func, _Public, _F(NameSpace_AddTypeCheck), TY_void, TY_NameSpace, MN_("addTypeCheck"), 2, TY_symbol, FN_keyword, TY_FuncTypeCheck, FN_func, DEND, }; KLIB kNameSpace_LoadMethodData(kctx, ns, MethodData, trace); }
.init = Tagger_Init, .free = Tagger_Free, }; static KDEFINE_CLASS MecabNodeDef = { STRUCTNAME(MecabNode), .cflag = kClass_Final, .init = MecabNode_Init, .free = MecabNode_Free, }; KonohaClass *cTagger = KLIB kNameSpace_DefineClass(kctx, ns, NULL, &TaggerDef, trace); KonohaClass *cMecabNode = KLIB kNameSpace_DefineClass(kctx, ns, NULL, &MecabNodeDef, trace); KDEFINE_METHOD MethodData[] = { _Public|_Const, _F(Tagger_new), TY_Tagger, TY_Tagger, MN_("new"), 0, _Public|_Const, _F(Tagger_Parse), TY_String, TY_Tagger, MN_("parse"), 1, TY_String, FN_("input"), _Public|_Const, _F(Tagger_NBestParse), TY_String, TY_Tagger, MN_("NBestParse"), 2, TY_int, FN_("n"), TY_String, FN_("input"), _Public|_Const, _F(Tagger_NBestInit), TY_String, TY_Tagger, MN_("NBestInit"), 1, TY_String, FN_("input"), _Public|_Const, _F(Tagger_NBestNext), TY_String, TY_Tagger, MN_("NBestNext"), 0, _Public|_Const, _F(Tagger_ParseToNode), TY_MecabNode, TY_Tagger, MN_("parseToNode"), 1, TY_String, FN_("input"), _Public|_Const, _F(Tagger_destroy), TY_void, TY_Tagger, MN_("destroy"), 0, _Public|_Const, _F(MecabNode_next), TY_MecabNode, TY_MecabNode, MN_("next"), 0, _Public|_Const, _F(MecabNode_prev), TY_MecabNode, TY_MecabNode, MN_("prev"), 0, _Public|_Const, _F(MecabNode_enext), TY_MecabNode, TY_MecabNode, MN_("enext"), 0, _Public|_Const, _F(MecabNode_bnext), TY_MecabNode, TY_MecabNode, MN_("bnext"), 0, _Public|_Const, _F(MecabNode_getSurface), TY_String, TY_MecabNode, MN_("getSurface"), 0, _Public|_Const, _F(MecabNode_getFeature), TY_String, TY_MecabNode, MN_("getFeature"), 0, _Public|_Const, _F(MecabNode_getLength), TY_int, TY_MecabNode, MN_("getLength"), 0, _Public|_Const, _F(MecabNode_getRLength), TY_int, TY_MecabNode, MN_("getRLength"), 0,
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"), _Public|_Static|_Const|_Im, _F(System_shutdown), TY_int, TY_System, MN_("shutdown"), 2, TY_int, FN_("fd"), TY_int, FN_("how"), _Public|_Static|_Const|_Im, _F(System_sockatmark), TY_int, TY_System, MN_("sockatmark"), 1, TY_int, FN_("fd"), _Public|_Static|_Const|_Im, _F(System_socket), TY_int, TY_System, MN_("socket"), 3, TY_int, FN_("family"), TY_int, FN_("type"), TY_int, FN_("protocol"), _Public|_Static|_Const|_Im, _F(System_socketpair), TY_int, TY_System, MN_("socketpair"), 4, TY_int, FN_("family"), TY_int, FN_("type"), TY_int, FN_("protocol"), TY_intArray, FN_("pairsock"), _Public|_Const|_Im, _F(SockAddr_new), TY_SockAddr, TY_SockAddr, MN_("new"), 0, // the function below uses Bytes
static kbool_t python_initPackage(KonohaContext *kctx, kNameSpace *ns, int argc, const char**args, kfileline_t pline) { python_init_count++; if(python_init_count == 1) { Py_Initialize(); } static KDEFINE_CLASS PythonDef = { STRUCTNAME(PyObject), .cflag = 0, .init = PyObject_init, .free = PyObject_free, .p = PyObject_p, }; KonohaClass *cPython = KLIB Konoha_defineClass(kctx, ns->packageId, ns->packageDomain, NULL, &PythonDef, pline); int TY_PyObject = cPython->typeId; KDEFINE_METHOD MethodData[] = { _Public|_Const|_Im|_Coercion, _F(PyObject_toBoolean), TY_Boolean, TY_PyObject, MN_to(TY_Boolean), 0, _Public|_Const|_Im|_Coercion, _F(Boolean_toPyObject), TY_PyObject, TY_Boolean, MN_to(TY_PyObject), 0, _Public|_Const|_Im|_Coercion, _F(PyObject_toInt), TY_Int, TY_PyObject, MN_to(TY_Int), 0, _Public|_Const|_Im|_Coercion, _F(Int_toPyObject), TY_PyObject, TY_Int, MN_to(TY_PyObject), 0, _Public|_Const|_Im|_Coercion, _F(PyObject_toString), TY_String, TY_PyObject, MN_to(TY_String), 0, _Public|_Const|_Im|_Coercion, _F(String_toPyObject), TY_PyObject, TY_String, MN_to(TY_PyObject), 0, _Public|_Const|_Im|_Coercion, _F(PyObject_toString), TY_String, TY_PyObject, MN_("toString"), 0, //_Public, _F(Array_add), TY_void, TY_Array, MN_("add"), 1, TY_0, FN_("value"), // [TODO] add following konoha class. //_Public|_Const|_Im|_Coercion, _F(PyObject_toList), TY_Array, TY_PyObject, MN_to(TY_Array), 0, //_Public|_Const|_Im|_Coercion, _F(Array_toPyObject), TY_PyObject, TY_Array, MN_to(TY_PyObject), 0, //_Public|_Const|_Im|_Coercion, _F(PyObject_toComplex), TY_Complex, TY_PyObject, MN_to(TY_Complex), 0, //_Public|_Const|_Im|_Coercion, _F(Complex_toPyObject), TY_PyObject, TY_Complex, MN_to(TY_PyObject), 0, //_Public|_Const|_Im|_Coercion, _F(PyObject_toBuffer), TY_Buffer, TY_PyObject, MN_to(TY_Buffer), 0, //_Public|_Const|_Im|_Coercion, _F(Buffer_toPyObject), TY_PyObject, TY_Buffer, MN_to(TY_PyObject), 0, //_Public|_Const|_Im|_Coercion, _F(PyObject_toTuple), TY_Tuple, TY_PyObject, MN_to(TY_Tuple), 0, //_Public|_Const|_Im|_Coercion, _F(Tuple_toPyObject), TY_PyObject, TY_Tuple, MN_to(TY_PyObject), 0, //_Public|_Const|_Im|_Coercion, _F(PyObject_toDict), TY_Dict, TY_PyObject, MN_to(TY_Dict), 0, //_Public|_Const|_Im|_Coercion, _F(Dict_toPyObject), TY_PyObject, TY_Dict, MN_to(TY_PyObject), 0, //_Public|_Const|_Im|_Coercion, _F(PyObject_toClass), TY_Class, TY_PyObject, MN_to(TY_Class), 0, //_Public|_Const|_Im|_Coercion, _F(Class_toPyObject), TY_PyObject, TY_Class, MN_to(TY_PyObject), 0, //_Public|_Const|_Im|_Coercion, _F(PyObject_asFunction), TY_Function, TY_PyObject, MN_to(TY_Function), 0, //_Public|_Const|_Im|_Coercion, _F(Function_toPyObject), TY_PyObject, TY_Function, MN_to(TY_PyObject), 0, //_Public|_Const|_Im|_Coercion, _F(PyObject_asMethod), TY_Method, TY_PyObject, MN_to(TY_Method), 0, //_Public|_Const|_Im|_Coercion, _F(Method_toPyObject), TY_PyObject, TY_Method, MN_to(TY_PyObject), 0, //_Public|_Const|_Im|_Coercion, _F(PyObject_toFile), TY_File, TY_PyObject, MN_to(TY_File), 0, //_Public|_Const|_Im|_Coercion, _F(File_toPyObject), TY_PyObject, TY_File, MN_to(TY_PyObject), 0, //_Public|_Const|_Im|_Coercion, _F(PyObject_toModule), TY_Module, TY_PyObject, MN_to(TY_Module), 0, //_Public|_Const|_Im|_Coercion, _F(Module_toPyObject), TY_PyObject, TY_Module, MN_to(TY_PyObject), 0, //_Public|_Const|_Im|_Coercion, _F(PyObject_toSeqIter), TY_SeqIter, TY_PyObject, MN_to(TY_SeqIter), 0, //_Public|_Const|_Im|_Coercion, _F(SeqIter_toPyObject), TY_PyObject, TY_SeqIter, MN_to(TY_PyObject), 0, //_Public|_Const|_Im|_Coercion, _F(PyObject_toSlice), TY_Slice, TY_PyObject, MN_to(TY_Slice), 0, //_Public|_Const|_Im|_Coercion, _F(Slice_toPyObject), TY_PyObject, TY_Slice, MN_to(TY_PyObject), 0, //_Public|_Const|_Im|_Coercion, _F(PyObject_toWeakref), TY_Weakref, TY_PyObject, MN_to(TY_Weakref), 0, //_Public|_Const|_Im|_Coercion, _F(Weakref_toPyObject), TY_PyObject, TY_Weakref, MN_to(TY_PyObject), 0, //_Public|_Const|_Im|_Coercion, _F(PyObject_toCapsule), TY_Capsule, TY_PyObject, MN_to(TY_Capsule), 0, //_Public|_Const|_Im|_Coercion, _F(Capsule_toPyObject), TY_PyObject, TY_Capsule, MN_to(TY_PyObject), 0, //_Public|_Const|_Im|_Coercion, _F(PyObject_toCell), TY_Cell, TY_PyObject, MN_to(TY_Cell), 0, //_Public|_Const|_Im|_Coercion, _F(Cell_toPyObject), TY_PyObject, TY_Cell, MN_to(TY_PyObject), 0, //_Public|_Const|_Im|_Coercion, _F(PyObject_toGen), TY_Gen, TY_PyObject, MN_to(TY_Gen), 0, //_Public|_Const|_Im|_Coercion, _F(Gen_toPyObject), TY_PyObject, TY_Gen, MN_to(TY_PyObject), 0, //_Public|_Const|_Im|_Coercion, _F(Date_toPyObject), TY_PyObject, TY_Date, MN_to(TY_PyObject), 0, //_Public|_Const|_Im|_Coercion, _F(PyObject_toDate), TY_Date, TY_PyObject, MN_to(TY_Date), 0, //_Public|_Const|_Im|_Coercion, _F(Set_toPyObject), TY_PyObject, TY_Set, MN_to(TY_PyObject), 0, //_Public|_Const|_Im|_Coercion, _F(PyObject_toSet), TY_Set, TY_PyObject, MN_to(TY_Set), 0, //_Public|_Const|_Im|_Coercion, _F(Code_toPyObject), TY_PyObject, TY_Code, MN_to(TY_PyObject), 0, //_Public|_Const|_Im|_Coercion, _F(PyObject_toCode), TY_Code, TY_PyObject, MN_to(TY_Code), 0, _Public|_Im, _F(Python_eval), TY_Boolean, TY_System, FN_("pyEval"), 1, TY_String, FN_("script"), _Public|_Im, _F(PyObject_import), TY_PyObject, TY_PyObject, FN_("import"), 1, TY_String, FN_("name"), _Public|_Im, _F(PyObject_), TY_PyObject, TY_PyObject, 0, 1, TY_PyObject, 0, DEND, }; KLIB kNameSpace_loadMethodData(kctx, ns, MethodData); if(IS_DefinedFloat()) { KDEFINE_METHOD MethodData[] = { _Public|_Const|_Im|_Coercion, _F(PyObject_toFloat), TY_Float, TY_PyObject, MN_to(TY_Float), 0, _Public|_Const|_Im|_Coercion, _F(Float_toPyObject), TY_PyObject, TY_Float, MN_to(TY_PyObject), 0, DEND, }; KLIB kNameSpace_loadMethodData(kctx, ns, MethodData); } return true; }
static kbool_t logpool_initPackage(KonohaContext *kctx, kNameSpace *ns, int argc, const char**args, kfileline_t pline) { int i; static KDEFINE_CLASS Def0 = { .structname = "LogPool"/*structname*/, .typeId = TY_newid/*cid*/, .init = RawPtr_init, .free = Logpool_free, }; KonohaClass *ct0 = KLIB Konoha_defineClass(kctx, ns->packageId, ns->packageDomain, NULL, &Def0, pline); static KDEFINE_CLASS Def1 = { .structname = "Log"/*structname*/, .typeId = TY_newid/*cid*/, .init = RawPtr_init, .free = Log_free, .p = Log_p, }; KonohaClass *ct1 = KLIB Konoha_defineClass(kctx, ns->packageId, ns->packageDomain, NULL, &Def1, pline); static KDEFINE_CLASS Def2 = { .structname = "PoolPlugin", .typeId = TY_newid, .init = RawPtr_init, .free = RawPtr_free, }; KonohaClass *ct2 = KLIB Konoha_defineClass(kctx, ns->packageId, ns->packageDomain, NULL, &Def2, pline); #define TY_Plugin ct2->typeId static KDEFINE_CLASS Def3 = { .structname = "", .typeId = TY_newid, .init = RawPtr_init, .free = RawPtr_free, }; Def3.superTypeId = ct2->typeId; static const char *names[] = { "Printer", "KeyFilter", "ValFilter", "React", "Timer", "Statics", "Copy", "Response", }; KonohaClass *tbls[8]; #define TY_Printer tbls[0]->typeId #define TY_KeyFilter tbls[1]->typeId #define TY_ValFilter tbls[2]->typeId #define TY_React tbls[3]->typeId #define TY_Timer tbls[4]->typeId #define TY_Statics tbls[5]->typeId #define TY_Copy tbls[6]->typeId #define TY_Response tbls[7]->typeId for (i = 0; i < 8; i++) { Def3.structname = names[i]; tbls[i] = KLIB Konoha_defineClass(kctx, ns->packageId, ns->packageDomain, NULL, &Def3, pline); } int FN_x = FN_("x"); int FN_y = FN_("y"); int FN_z = FN_("z"); KDEFINE_METHOD MethodData[] = { _P|_C, _F(LogPool_new), TY_Logpool, TY_Logpool, MN_("new"), 2, TY_String, FN_x, TY_Int, FN_y, _P|_C, _F(LogPool_get), TY_Log, TY_Logpool, MN_("get"), 0, _P|_C, _F(LogPool_loadFile), TY_void, TY_Logpool, MN_("loadFile"), 2, TY_String, FN_x, TY_String, FN_y, _P|_C, _F(Log_get_), TY_String, TY_Log, MN_("get"), 1, TY_String, FN_x, _P|_S, _F(Printer_create ), TY_Plugin, TY_Printer , MN_("create"), 0, _P|_S, _F(KeyFilter_create), TY_Plugin, TY_KeyFilter, MN_("create"), 1, TY_String, FN_x, _P|_S, _F(ValFilter_create), TY_Plugin, TY_ValFilter, MN_("create"), 3, TY_String, FN_x, TY_String, FN_y, TY_String, FN_z, _P|_S, _F(React_create ), TY_Plugin, TY_React , MN_("create"), 2, TY_String, FN_x, TY_String, FN_y, _P|_S, _F(Timer_create ), TY_Plugin, TY_Timer , MN_("create"), 3, TY_Int, FN_x, TY_Int, FN_y, TY_Int, FN_z, _P|_S, _F(Statics_create ), TY_Plugin, TY_Statics , MN_("create"), 3, TY_Func, FN_x, TY_Func, FN_y, TY_Func, FN_z, _P|_S, _F(Copy_create ), TY_Plugin, TY_Copy , MN_("create"), 0, _P|_S, _F(Response_create ), TY_Plugin, TY_Response , MN_("create"), 1, TY_Object, FN_x, _P , _F(PoolPlugin_apply ), TY_void, TY_Plugin , MN_("apply"), 1, TY_Plugin, FN_x, _P , _F(PoolPlugin_failed), TY_void, TY_Plugin , MN_("failed"), 1, TY_Plugin, FN_x, DEND, }; KLIB kNameSpace_loadMethodData(kctx, ns, MethodData); return true; } static kbool_t logpool_setupPackage(KonohaContext *kctx, kNameSpace *ns, isFirstTime_t isFirstTime, kfileline_t pline) { return true; } static kbool_t logpool_initNameSpace(KonohaContext *kctx, kNameSpace *ns, kfileline_t pline) { return true; } static kbool_t logpool_setupNameSpace(KonohaContext *kctx, kNameSpace *ns, kfileline_t pline) { return true; } KDEFINE_PACKAGE* logpool_init(void) { logpool_global_init(LOGPOOL_DEFAULT); static KDEFINE_PACKAGE d = { KPACKNAME("logpool", "1.0"), .initPackage = logpool_initPackage, .setupPackage = logpool_setupPackage, .initNameSpace = logpool_initNameSpace, .setupNameSpace = logpool_setupNameSpace, }; return &d; }
static kbool_t float_defineMethod(KonohaContext *kctx, kNameSpace *ns, KTraceInfo *trace) { KRequireKonohaCommonModule(trace); if(CT_Float == NULL) { KDEFINE_CLASS defFloat = {0}; SETUNBOXNAME(defFloat, float); defFloat.cstruct_size = sizeof(kFloat); defFloat.cflag = CFLAG_int; defFloat.init = Float_Init; defFloat.p = Float_p; CT_Float = KLIB kNameSpace_DefineClass(kctx, ns, NULL, &defFloat, trace); } int FN_x = FN_("x"); KDEFINE_METHOD MethodData[] = { _Public|_Const|_Im, _F(Float_opPlus), TY_float, TY_float, MN_("+"), 0, _Public|_Const|_Im, _F(Float_opADD), TY_float, TY_float, MN_("+"), 1, TY_float, FN_x, _Public|_Const|_Im, _F(Int_opADD), TY_float, TY_int, MN_("+"), 1, TY_float, FN_x, _Public|_Const|_Im, _F(Float_opSUB), TY_float, TY_float, MN_("-"), 1, TY_float, FN_x, _Public|_Const|_Im, _F(Int_opSUB), TY_float, TY_int, MN_("-"), 1, TY_float, FN_x, _Public|_Const|_Im, _F(Float_opMUL), TY_float, TY_float, MN_("*"), 1, TY_float, FN_x, _Public|_Im, _F(Float_opDIV), TY_float, TY_float, MN_("/"), 1, TY_float, FN_x, _Public|_Const|_Im, _F(Float_opEQ), TY_boolean, TY_float, MN_("=="), 1, TY_float, FN_x, _Public|_Const|_Im, _F(Float_opNEQ), TY_boolean, TY_float, MN_("!="), 1, TY_float, FN_x, _Public|_Const|_Im, _F(Float_opLT), TY_boolean, TY_float, MN_("<"), 1, TY_float, FN_x, _Public|_Const|_Im, _F(Float_opLTE), TY_boolean, TY_float, MN_("<="), 1, TY_float, FN_x, _Public|_Const|_Im, _F(Float_opGT), TY_boolean, TY_float, MN_(">"), 1, TY_float, FN_x, _Public|_Const|_Im, _F(Float_opGTE), TY_boolean, TY_float, MN_(">="), 1, TY_float, FN_x, _Public|_Const|_Im, _F(Int_opMUL), TY_float, TY_int, MN_("*"), 1, TY_float, FN_x, _Public|_Im, _F(Int_opDIV), TY_float, TY_int, MN_("/"), 1, TY_float, FN_x, _Public|_Const|_Im, _F(Int_opEQ), TY_boolean, TY_int, MN_("=="), 1, TY_float, FN_x, _Public|_Const|_Im, _F(Int_opNEQ), TY_boolean, TY_int, MN_("!="), 1, TY_float, FN_x, _Public|_Const|_Im, _F(Int_opLT), TY_boolean, TY_int, MN_("<"), 1, TY_float, FN_x, _Public|_Const|_Im, _F(Int_opLTE), TY_boolean, TY_int, MN_("<="), 1, TY_float, FN_x, _Public|_Const|_Im, _F(Int_opGT), TY_boolean, TY_int, MN_(">"), 1, TY_float, FN_x, _Public|_Const|_Im, _F(Int_opGTE), TY_boolean, TY_int, MN_(">="), 1, TY_float, FN_x, _Public|_Const|_Im|_Coercion, _F(Float_toInt), TY_int, TY_float, MN_to(TY_int), 0, _Public|_Const|_Im|_Coercion, _F(Int_toFloat), TY_float, TY_int, MN_to(TY_float), 0, _Public|_Const|_Im, _F(Float_toString), TY_String, TY_float, MN_to(TY_String), 0, _Public|_Const|_Im, _F(String_toFloat), TY_float, TY_String, MN_to(TY_float), 0, _Public|_Const|_Im, _F(Float_opMINUS), TY_float, TY_float, MN_("-"), 0, DEND, }; KLIB kNameSpace_LoadMethodData(kctx, ns, MethodData, trace); KDEFINE_FLOAT_CONST FloatData[] = { {"FLOAT_EPSILON", TY_float, DBL_EPSILON}, {"Infinity", TY_float, INFINITY}, {"NaN", TY_float, NAN}, {NULL} /* sentinel */ }; KLIB kNameSpace_LoadConstData(kctx, ns, KonohaConst_(FloatData), false/*isOverride*/, trace); return true; }
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); } ktype_t TY_StringArray0 = CT_StringArray0->typeId; KDEFINE_METHOD MethodData[] = { /*JS*/_Public|_Const|_Im, _F(RegExp_getglobal), TY_boolean, TY_RegExp, MN_("getglobal"), 0, /*JS*/_Public|_Const|_Im, _F(RegExp_getignoreCase), TY_boolean, TY_RegExp, MN_("getignoreCase"), 0, /*JS*/_Public|_Const|_Im, _F(RegExp_getmultiline), TY_boolean, TY_RegExp, MN_("getmultiline"), 0, /*JS*/_Public|_Const|_Im, _F(RegExp_getsource), TY_String, TY_RegExp, MN_("getsource"), 0, /*JS*/_Public|_Const|_Im, _F(RegExp_getlastIndex), TY_int, TY_RegExp, MN_("getlastIndex"), 0, /*JS*/_Public|_Im, _F(String_Match), TY_StringArray0, TY_String, MN_("match"), 1, TY_RegExp, FN_("regexp"), /*JS*/_Public|_Const|_Im, _F(String_replace), TY_String, TY_String, MN_("replace"), 2, TY_RegExp, FN_("searchvalue"), TY_String, FN_("newvalue"), /*JS*/_Public|_Const|_Im, _F(String_search), TY_int, TY_String, MN_("search"), 1, TY_RegExp, FN_("searchvalue"), /*JS*/_Public|_Im, _F(String_split), TY_StringArray0, TY_String, MN_("split"), 1, TY_RegExp, FN_("separator"), /*JS*/_Public|_Im, _F(String_splitWithLimit), TY_StringArray0, TY_String, MN_("split"), 2, TY_RegExp, FN_("separator"), TY_int, FN_("limit"), /*JS*/_Public|_Const, _F(RegExp_new), TY_RegExp, TY_RegExp, MN_("new"), 1, TY_String, FN_("pattern"), /*JS*/_Public|_Const, _F(RegExp_new2), TY_RegExp, TY_RegExp, MN_("new"), 2, TY_String, FN_("pattern"), TY_String, FN_("option"), /*JS*/_Public|_Const, _F(RegExp_exec), TY_StringArray0, TY_RegExp, MN_("exec"), 1, TY_String, FN_("str"), /*JS*/_Public|_Const|_Im, _F(RegExp_test), TY_boolean, TY_RegExp, MN_("test"), 1, TY_String, FN_("str"), DEND, };
static kbool_t jansson_initPackage(KonohaContext *kctx, kNameSpace *ns, int argc, const char**args, KTraceInfo *trace) { KRequirePackage("konoha.float", trace); KDEFINE_CLASS JsonDef = { .structname = "Json", .typeId = TY_newid, .cflag = kClass_Final, .init = Jansson_init, .free = Jansson_free, .p = Jansson_p, }; KonohaClass *cJson = KLIB kNameSpace_defineClass(kctx, ns, NULL, &JsonDef, trace); ktype_t TY_JsonArray = CT_JsonArray->typeId; ktype_t TY_StringArray0 = CT_StringArray0->typeId; int FN_k = FN_("key"); int FN_v = FN_("value"); KDEFINE_METHOD MethodData[] = { _Public|_Const|_Im, _F(Json_dump), TY_String, TY_Json, MN_("dump"), 0, _Public|_Const|_Im, _F(Json_getJson), TY_Json, TY_Json, MN_("getJson"), 1, TY_String, FN_k, _Public|_Const|_Im, _F(Json_getArray), TY_JsonArray, TY_Json, MN_("getArray"), 1, TY_String, FN_k, _Public|_Const|_Im, _F(Json_getBool), TY_boolean, TY_Json, MN_("getBool"), 1, TY_String, FN_k, _Public|_Const|_Im, _F(Json_getFloat), TY_float, TY_Json, MN_("getFloat"), 1, TY_String, FN_k, _Public|_Const|_Im, _F(Json_getInt), TY_int, TY_Json, MN_("getInt"), 1, TY_String, FN_k, _Public|_Const|_Im, _F(Json_getString), TY_String, TY_Json, MN_("getString"), 1, TY_String, FN_k, _Public, _F(Json_new), TY_Json, TY_Json, MN_("new"), 0, _Public|_Static|_Const|_Im, _F(Json_parse), TY_Json, TY_Json, MN_("parse"), 1, TY_String, FN_v, _Public, _F(Json_setJson), TY_void, TY_Json, MN_("setJson"), 2, TY_String, FN_k, TY_Json, FN_v, _Public, _F(Json_setArray), TY_void, TY_Json, MN_("setArray"), 2, TY_String, FN_k, TY_JsonArray, FN_v, _Public, _F(Json_setBool), TY_void, TY_Json, MN_("setBool"), 2, TY_String, FN_k, TY_boolean, FN_v, _Public, _F(Json_setFloat), TY_void, TY_Json, MN_("setFloat"), 2, TY_String, FN_k, TY_float, FN_v, _Public, _F(Json_setInt), TY_void, TY_Json, MN_("setInt"), 2, TY_String, FN_k, TY_int, FN_v, _Public, _F(Json_setString), TY_void, TY_Json, MN_("setString"), 2, TY_String, FN_k, TY_String, FN_v, _Public|_Const|_Im, _F(Json_getKeys), TY_StringArray0, TY_Json, MN_("getKeys"), 0, _Public|_Const|_Im, _F(Json_dump), TY_String, TY_JsonArray, MN_("dump"), 0, _Public, _F(JsonArray_newArray), TY_JsonArray, TY_JsonArray, MN_("newArray"), 1, TY_int, FN_("size"), _Public|_Const|_Im, _F(JsonArray_get), TY_Json, TY_JsonArray, MN_("get"), 1, TY_int, FN_("idx"), _Public, _F(JsonArray_add), TY_void, TY_JsonArray, MN_("add"), 1, TY_Json, FN_v, _Public|_Const|_Im, _F(JsonArray_getSize), TY_int, TY_JsonArray, MN_("getSize"), 0, DEND, }; KLIB kNameSpace_loadMethodData(kctx, ns, MethodData); return true; } static kbool_t jansson_setupPackage(KonohaContext *kctx, kNameSpace *ns, isFirstTime_t isFirstTime, KTraceInfo *trace) { return true; } KDEFINE_PACKAGE* jansson_init(void) { static KDEFINE_PACKAGE d = { KPACKNAME("jansson", "1.0"), .initPackage = jansson_initPackage, .setupPackage = jansson_setupPackage, }; return &d; }