예제 #1
0
// @SmartReturn Object Prototype.get(Symbol symbol)
static KMETHOD Prototype_get(KonohaContext *kctx, KonohaStack *sfp)
{
	KClass *targetClass = KGetReturnType(sfp);
	DBG_P("requesting type=%s", KClass_text(targetClass));
	ksymbol_t symbol = sfp[1].intValue;
	KKeyValue *kvs = KLIB kObjectProto_GetKeyValue(kctx, sfp[0].asObject, symbol);
	if(kvs != NULL) {
		KClass *c = KClass_(kvs->attrTypeId);
		if(targetClass == c) {
			if(KClass_Is(UnboxType, targetClass)) {
				KReturnUnboxValue(kvs->unboxValue);
			}
			else {
				KReturnField(kvs->ObjectValue);
			}
		}
		DBG_P("requesting type=%s instanceof %s ? %d", KClass_text(c), KClass_text(targetClass), c->isSubType(kctx, c, targetClass));
		if(c->isSubType(kctx, c, targetClass)) {
			if(KClass_Is(UnboxType, c)) {
				if(KClass_Is(UnboxType, targetClass)) {
					KReturnUnboxValue(kvs->unboxValue);
				}
				else {
					DBG_P("boxing type=%s instanceof %s ? %d", KClass_text(c), KClass_text(targetClass), c->isSubType(kctx, c, targetClass));
					KReturn(KLIB new_kObject(kctx, OnStack, c, kvs->unboxValue));
				}
			}
			KReturnField(kvs->ObjectValue);
		}
	}
	KReturnUnboxValue(0);  // return default value
}
예제 #2
0
static kMap *knh_parseReply(CTX ctx, char *reply)
{
    int rc;
    char **rv = NULL;
    kMap *rmap = NULL;
    DBG_P("HTTP-reply: %s", reply);
    rc = oauth_split_url_parameters(reply, &rv);
    knh_qsort(rv, rc, sizeof(char *), oauth_cmpstringp);
    if (rv != NULL) {
        rmap = new_DataMap(ctx);
        const char *key, *val;
        int i;
        for (i = 0; i < rc; i++) {
            DBG_P("rv[%d]=%s", i, rv[i]);
            val = strchr(rv[i], '=');
            if (val != NULL) {
                val += 1;
                key = rv[i];
                rv[i][val - rv[i] - 1] = '\0';
                knh_DataMap_setString(ctx, rmap, key, val);
            }
            free(rv[i]);
        }
        free(rv);
    }
    return rmap;
}
예제 #3
0
static KMETHOD Statement_for(KonohaContext *kctx, KonohaStack *sfp)
{
	VAR_Statement(stmt, gma);
	DBG_P("for statement .. ");
	int isOkay = false;
	if(SUGAR kStmt_TypeCheckByName(kctx, stmt, KW_ExprPattern, gma, CT_INFER, 0)) {
		kNameSpace *ns = Stmt_ns(stmt);
		kToken *TypeToken = SUGAR kStmt_GetToken(kctx, stmt, KW_TypePattern, NULL);
		kToken *VariableToken  = SUGAR kStmt_GetToken(kctx, stmt, KW_SymbolPattern, NULL);
		DBG_P("typeToken=%p, varToken=%p", TypeToken, VariableToken);
		kExpr *IteratorExpr = SUGAR kStmt_GetExpr(kctx, stmt, KW_ExprPattern, NULL);
		if(!TY_isIterator(IteratorExpr->attrTypeId)) {
			kMethod *mtd = KLIB kNameSpace_GetMethodByParamSizeNULL(kctx, ns, CT_(IteratorExpr->attrTypeId), MN_to(TY_Iterator), 0, MethodMatch_NoOption);
			if(mtd == NULL) {
				kStmtExpr_Message(kctx, stmt, IteratorExpr, ErrTag, "expected Iterator expression after in");
				KReturnUnboxValue(false);
			}
			IteratorExpr = SUGAR new_TypedCallExpr(kctx, stmt, gma, CT_INFER, mtd, 1, IteratorExpr);
			kStmt_setObject(kctx, stmt, KW_ExprPattern, IteratorExpr);
		}
		kBlock *block = new_MacroBlock(kctx, stmt, new_TypeToken(kctx, ns, CT_(IteratorExpr->attrTypeId)), new_ParsedExprToken(kctx, ns, IteratorExpr), TypeToken, VariableToken);
		kStmt *IfStmt = block->StmtList->StmtItems[1]; // @see macro;
		kStmt_appendBlock(kctx, IfStmt, SUGAR kStmt_GetBlock(kctx, stmt, ns, KW_BlockPattern, NULL));
		kStmt_Set(CatchBreak, IfStmt, true);
		kStmt_Set(CatchContinue, IfStmt, true);
		isOkay = SUGAR kBlock_TypeCheckAll(kctx, block, gma);
		if(isOkay) {
			kStmt_typed(IfStmt, LOOP);
			kStmt_setObject(kctx, stmt, KW_BlockPattern, block);
			kStmt_typed(stmt, BLOCK);
		}
	}
	KReturnUnboxValue(isOkay);
}
예제 #4
0
파일: ds2408.c 프로젝트: rdnzl/owslave
void do_command(u_char cmd)
{
	if(cmd == C_READ_PIO) {
		DBG_P(":I");
		do_read_pio();
	} else {
		DBG_P("?CI");
		DBG_X(cmd);
		set_idle();
	}
}
예제 #5
0
static KMETHOD Expression_Bracket(KonohaContext *kctx, KonohaStack *sfp)
{
	VAR_Expression(stmt, tokenList, beginIdx, operatorIdx, endIdx);
	KonohaClass *genericsClass = NULL;
	kNameSpace *ns = Stmt_ns(stmt);
	int nextIdx = SUGAR TokenUtils_ParseTypePattern(kctx, ns, tokenList, beginIdx, endIdx, &genericsClass);
	if(nextIdx != -1) {  // to avoid Func[T]
		KReturn(SUGAR kStmt_ParseOperatorExpr(kctx, stmt, tokenList->TokenItems[beginIdx]->resolvedSyntaxInfo, tokenList, beginIdx, beginIdx, endIdx));
	}
	kToken *currentToken = tokenList->TokenItems[operatorIdx];
	if(beginIdx == operatorIdx) {
		/* transform '[ Value1, Value2, ... ]' to '(Call Untyped new (Value1, Value2, ...))' */
		DBG_ASSERT(currentToken->resolvedSyntaxInfo->keyword == KW_BracketGroup);
		kExpr *arrayExpr = SUGAR new_UntypedCallStyleExpr(kctx, currentToken->resolvedSyntaxInfo, 2, currentToken, K_NULL);
		KReturn(SUGAR kStmt_AddExprParam(kctx, stmt, arrayExpr, currentToken->subTokenList, 0, kArray_size(currentToken->subTokenList), NULL));
	}
	else {
		kExpr *leftExpr = SUGAR kStmt_ParseExpr(kctx, stmt, tokenList, beginIdx, operatorIdx, NULL);
		if(leftExpr == K_NULLEXPR) {
			KReturn(leftExpr);
		}
		if(leftExpr->syn->keyword == SYM_("new")) {  // new int[100], new int[]();
			DBG_P("cur:%d, beg:%d, endIdx:%d", operatorIdx, beginIdx, endIdx);
			size_t subTokenSize = kArray_size(currentToken->subTokenList);
			if(subTokenSize == 0) {
				/* transform 'new Type0 [ ]' => (Call Type0 new) */
				kExpr_Setsyn(leftExpr, SYN_(ns, KW_ExprMethodCall));
			} else {
				/* transform 'new Type0 [ Type1 ] (...) => new 'Type0<Type1>' (...) */
				KonohaClass *classT0 = NULL;
				kArray *subTokenList = currentToken->subTokenList;
				int beginIdx = -1;
				if(kArray_size(subTokenList) > 0) {
					beginIdx = SUGAR TokenUtils_ParseTypePattern(kctx, ns, subTokenList, 0, kArray_size(subTokenList), &classT0);
				}
				beginIdx = (beginIdx == -1) ? 0 : beginIdx;
				kExpr_Setsyn(leftExpr, SYN_(ns, KW_ExprMethodCall));
				DBG_P("currentToken->subtoken:%d", kArray_size(subTokenList));
				leftExpr = SUGAR kStmt_AddExprParam(kctx, stmt, leftExpr, subTokenList, beginIdx, kArray_size(subTokenList), "[");
			}
		}
		else {
			/* transform 'Value0 [ Value1 ]=> (Call Value0 get (Value1)) */
			kTokenVar *tkN = /*G*/new_(TokenVar, 0, OnGcStack);
			tkN->resolvedSymbol= MN_toGETTER(0);
			tkN->uline = currentToken->uline;
			SugarSyntax *syn = SYN_(Stmt_ns(stmt), KW_ExprMethodCall);
			leftExpr  = SUGAR new_UntypedCallStyleExpr(kctx, syn, 2, tkN, leftExpr);
			leftExpr = SUGAR kStmt_AddExprParam(kctx, stmt, leftExpr, currentToken->subTokenList, 0, kArray_size(currentToken->subTokenList), "[");
		}
		KReturn(SUGAR kStmt_RightJoinExpr(kctx, stmt, leftExpr, tokenList, operatorIdx + 1, endIdx));
	}
}
static int tokenize_file(OE oe) {
	uint lbuffer = 1060365;
	uint ands = 0, xors = 0, invs = 0, nums = 0, tokens = 0;
	Tokenizer tk = 0;
	Token tok = {0};
	byte * buffer = oe->getmem(lbuffer);
	uint fp = 0;
	oe->open("file ../test/AES",&fp);
	oe->read(fp,buffer,&lbuffer);
	oe->close(fp);
	tk = FunCallTokenizer_New(oe);
	tk->start(buffer,lbuffer);

	do {
		tk->nextToken(&tok);
		if (tok.type == INV) invs += 1;
		if (tok.type == AND) ands +=1;
		if (tok.type == XOR) xors += 1;
		if (tok.type == NUM) nums += 1;
		tokens++;
	} while(tok.type != DONE);

	DBG_P(oe,"\nANDS: %u\nXORS: %u\nINVS: %u\nNUMS: %u\nTOKENS: %u\n",ands,xors,invs,nums,tokens);
	oe->putmem(buffer);
	return ands == 6800 && xors == 24448 && nums == 139136 && tokens == 172076 && invs == 1691;
}
예제 #7
0
static KMETHOD Statement_try(KonohaContext *kctx, KonohaStack *sfp)
{
	VAR_TypeCheck(stmt, ns, reqc);
	DBG_P("try statement .. \n");
	int ret = false;
	//kNode *tryNode, *catchNode, *finallyNode;
	//tryNode = SUGAR kNode_GetNode(kctx, stmt, NULL, KSymbol_NodePattern, K_NULLBLOCK);
	//ret = SUGAR TypeCheckBlock(kctx, tryNode,   gma);
	//if(ret == false) {
	//	KReturnUnboxValue(ret);
	//}

	//catchNode   = SUGAR kNode_GetNode(kctx, stmt, NULL, KSymbol_("catch"),   K_NULLBLOCK);
	//finallyNode = SUGAR kNode_GetNode(kctx, stmt, NULL, KSymbol_("finally"), K_NULLBLOCK);
	//ret = SUGAR TypeCheckBlock(kctx, tryNode,   gma);
	//ret = SUGAR TypeCheckBlock(kctx, catchNode, gma);
	//if(ret == false) {
	//	KReturnUnboxValue(ret);
	//}
	//if(finallyNode) {
	//	ret = SUGAR TypeCheckBlock(kctx, finallyNode, gma);
	//}
	//if(ret) {
	//	kNode_Type(stmt, TRY);
	//}
	KReturnUnboxValue(ret);
}
예제 #8
0
int main (int argc, char* argv[]) {
	int i;

	if(argc != 3) {
		usage(argv[0]);
		return -1;
	}

	CONNECTION *my_conn = ALLOC_SOCKET();
	DBG_P("Socket allocated\n");

	SET_LOCAL_NAME(my_conn, argv[1]);
	SET_DEST_NAME(my_conn, argv[2]);

	printf("Dest name: %s\n", GET_DEST_NAME(my_conn));

	SET_TRANSPORT(my_conn, SOCK_STREAM);
	
	SET_SERVICE(my_conn, "http");

	if( 0 > CONNECT( my_conn )  )
		return -1;

	char* msg = "Hello remote node!";
	SEND( my_conn, msg, strlen(msg) );

	CLOSE( my_conn );
}
예제 #9
0
static void kMethod_genCode(KonohaContext *kctx, kMethod *mtd, kBlock *bk)
{
	DBG_P("START CODE GENERATION..");
	INIT_GCSTACK();
	if(ctxcode == NULL) {
		kmodcode->h.setup(kctx, NULL, 0);
	}
	KLIB kMethod_setFunc(kctx, mtd, MethodFunc_runVirtualMachine);
	DBG_ASSERT(kArray_size(ctxcode->codeList) == 0);
	kBasicBlock* lbINIT  = new_BasicBlockLABEL(kctx);
	kBasicBlock* lbBEGIN = new_BasicBlockLABEL(kctx);
	ctxcode->lbEND = new_BasicBlockLABEL(kctx);
	PUSH_GCSTACK(lbINIT);
	PUSH_GCSTACK(lbBEGIN);
	PUSH_GCSTACK(ctxcode->lbEND);
	ctxcode->currentWorkingBlock = lbINIT;
//	BUILD_pushLABEL(kctx, NULL, lbBEGIN, lbEND);
	ASM(THCODE, _THCODE);
	ASM(CHKSTACK, 0);
	ASM_LABEL(kctx, lbBEGIN);
	BLOCK_asm(kctx, bk, 0);
	ASM_LABEL(kctx, ctxcode->lbEND);
	if (mtd->mn == MN_new) {
		ASM(NMOV, OC_(K_RTNIDX), OC_(0), CT_(mtd->typeId));   // FIXME: Type 'This' must be resolved
	}
	ASM(RET);
	assert(ctxcode->lbEND);/* scan-build: remove warning */
//	BUILD_popLABEL(kctx);
	BUILD_compile(kctx, mtd, lbINIT, ctxcode->lbEND);
	ctxcode->lbEND = NULL;
	RESET_GCSTACK();
}
예제 #10
0
파일: evidence.c 프로젝트: utrhira/mpik
/* added by Wakamori */
static kbool_t method_isPermissionAllowed(CTX ctx, kMethod *mtd)
{
	kDictMap *dmap = ctx->share->securityDictMap;
	CWB_t cwbbuf, *cwb = CWB_open0(ctx, &cwbbuf);
	CWB_write(ctx, cwb, S_tobytes(ClassTBL(mtd->cid)->sname));
	CWB_putc(ctx, cwb, '.');
	CWB_write(ctx, cwb, B(MN__(mtd->mn)));
	DBG_P("[methodname] : %s", CWB_tobytes(cwb).text);
	const char *idx, *p = role;
	while (p[0] != '\0') {
		idx = strchr((const char *)p, ',');
		kArray *a = NULL;
		if (idx != NULL) {
			a = (kArray *)knh_DictMap_getNULL(ctx, dmap, new_bytes2(p, idx - p));
			p = idx + 1;
		} else {
			a = (kArray *)knh_DictMap_getNULL(ctx, dmap, B(p));
			p += knh_strlen(p);
		}
		if (a != NULL) {
			int i;
			for (i = 0; i < knh_Array_size(a); i++) {
				const char *s = S_totext((kString*)knh_Array_n(a, i));
				if (strstr(s, CWB_tobytes(cwb).text) != NULL
					|| strstr(s, "all") != NULL) {
					// this method is allowed to be executed by this role
					CWB_close0(ctx, cwb);
					return 1;
				}
			}
		}
	}
	CWB_close0(ctx, cwb);
	return 0;
}
예제 #11
0
파일: MiniVM.c 프로젝트: imasahiro/konoha3
static kbool_t KBuilder_VisitMethodCallNode(KonohaContext *kctx, KBuilder *builder, kNode *expr, void *thunk)
{
	kshort_t a = AssignStack(thunk), espidx = expr->stackbase, thisidx = espidx + K_CALLDELTA;
	DBG_ASSERT(a <= espidx);
	kMethod *mtd = CallNode_getMethod(expr);
	DBG_ASSERT(IS_Method(mtd));
	int i, s = kMethod_Is(Static, mtd) ? 2 : 1;
	int argc = CallNode_getArgCount(expr);
	for (i = s; i < argc + 2; i++) {
		intptr_t a = thisidx + i - 1;
		kNode *paramNode = kNode_At(expr, i);
		if(!kNode_IsValue(paramNode) && paramNode->stackbase != a) {
			DBG_P("a=%d, stackbase=%d", a, paramNode->stackbase);
			DBG_ASSERT(paramNode->stackbase == a);
		}
		SUGAR VisitNode(kctx, builder, paramNode, &a);
	}
	if(kMethod_Is(Final, mtd) || !kMethod_Is(Virtual, mtd)) {
		ASM(NSET, NC_(thisidx-1), (intptr_t)mtd, KClass_Method);
		if(kMethod_Is(Virtual, mtd)) {
			// set namespace to enable method lookups
			ASM(NSET, OC_(thisidx-2), (intptr_t)kNode_ns(expr), KClass_NameSpace);
		}
	}
	else {
		ASM(NSET, OC_(thisidx-2), (intptr_t)kNode_ns(expr), KClass_NameSpace);
		ASM(LOOKUP, SFP_(thisidx), kNode_ns(expr), mtd);
	}
	int esp_ = SFP_(espidx + argc + K_CALLDELTA + 1);
	ASM(CALL, builder->common.uline, SFP_(thisidx), esp_, KLIB Knull(kctx, KClass_(expr->attrTypeId)));
	ReAssignNonValueNode(kctx, builder, a, expr);
	return true;
}
예제 #12
0
//## cid Object.tocid();
static KMETHOD Object_tocid(KonohaContext *kctx, KonohaStack *sfp)
{
	kObject *o = sfp[0].asObject;
	ktype_t cid = O_typeId(o);
	DBG_P(">>> Class=%s, cid=%d", SYM_t(CT_(cid)->classNameSymbol), cid);
	KReturnUnboxValue(cid);
}
예제 #13
0
파일: runtime.c 프로젝트: utrhira/mpik
static void opt_O(CTX ctx, int mode, const char *optstr)
{
	DBG_P("OPTIMIZATION %d", mode);
	if(mode == 0) {
		//DP(ctx->gma)->cflag = 0; // NOTHING
	}
}
예제 #14
0
파일: os.c 프로젝트: shinpei/konoha-wand
knh_String_t* knh_path_newString(CTX ctx, knh_path_t *ph, int hasScheme)
{
	knh_uchar_t *ubuf = P_ubuf(ph);
	if(ph->isRealPath) {
		int hasUTF8 = 0;
		size_t i;
		for(i = ph->pbody; i < ph->plen; i++) {
			int ch = ubuf[i];
			if(ch == '\\') {
				ubuf[i] = '/';
			}
			if(ch > 127) hasUTF8 = 1;
		}
		if(hasUTF8) {
			KNH_TODO("multibytes file path");
		}
	}
	knh_bytes_t t = {{P_text(ph)}, ph->plen};
	if(!hasScheme) {
		t.text = t.text + ph->pbody;
		t.len = t.len - ph->pbody;
	}
	DBG_P("ph='%s', size=%d", P_text(ph), ph->plen);
	return new_String_(ctx, CLASS_String, t, NULL);
}
예제 #15
0
static void DumpVirtualCode(KonohaContext *kctx, KVirtualCode *c)
{
	KBuffer wb;
	KLIB KBuffer_Init(&(kctx->stack->cwb), &wb);
	WriteVirtualCode(kctx, &wb, c);
	DBG_P(">>>\n%s", KLIB KBuffer_text(kctx, &wb, EnsureZero));
	KLIB KBuffer_Free(&wb);
}
예제 #16
0
//## void Token.setKeyword(symbol keyword);
static KMETHOD Token_setUnresolvedTokenType(KonohaContext *kctx, KonohaStack *sfp)
{
	kTokenVar *tk = (kTokenVar *) sfp[0].asToken;
	ksymbol_t keyword = (ksymbol_t)sfp[1].intValue;
	tk->unresolvedTokenType = keyword;
	DBG_P("setkeyword=%s%s", PSYM_t(keyword));
	KReturnVoid();
}
예제 #17
0
static KMETHOD Expression_isNotNull(KonohaContext *kctx, KonohaStack *sfp)
{
	VAR_Expression(stmt, tokenList, beginIdx, opIdx, endIdx);
	if(opIdx + 2 == endIdx) {
		DBG_P("checking .. x != null");
		kTokenVar *tk = tokenList->TokenVarItems[opIdx+1];
		if(tk->symbol == KSymbol_("null") || tk->symbol == KSymbol_("NULL")) {
			kNameSpace *ns = kNode_ns(stmt);
			tk->symbol = KSymbol_("IsNotNull");
			tk->resolvedSyntaxInfo = tokenList->TokenVarItems[opIdx]->resolvedSyntaxInfo;
			SUGAR kNode_Op(kctx, stmt, tk, 1, SUGAR ParseNewNode(kctx, ns, tokenList, &beginIdx, opIdx, ParseExpressionOption, NULL));
			KReturnUnboxValue(opIdx + 2);
		}
	}
	DBG_P("checking parent .. != ..");
	KReturnUnboxValue(-1);
}
예제 #18
0
static void knh_getToken(ksfp_t *sfp, AccessToken_t *token)
{
    kObject *consumer = sfp[0].ox->fields[0];
    kObject *rtoken = sfp[0].ox->fields[1];
    if (IS_NOTNULL(consumer)) {
        kObject *of = (kObject *)consumer;
        token->key = S_totext((kString*)of->fields[0]);
        token->secret = S_totext((kString*)of->fields[1]);
    }
    if (IS_NOTNULL(rtoken)) {
        kObject *of = (kObject *)rtoken;
        token->rtoken = S_totext((kString *)of->fields[0]);
        token->rtoken_secret = S_totext((kString *)of->fields[1]);
    }
    DBG_P("consumer_key: %s, consumer_secret: %s", token->key, token->secret);
    DBG_P("request_token: %s, request_token_secret: %s", token->rtoken, token->rtoken_secret);
}
예제 #19
0
static knh_bool_t isCalledMethod(Ctx *ctx, knh_sfp_t *sfp)
{
	knh_Method_t *mtd = sfp[0].callmtd;
	if(knh_isObject(ctx, mtd) && IS_Method(mtd)) {
		DBG_P("shift=%d, pc=%d", sfp[-2].shift, sfp[-1].pc);
		return 1;
	}
	return 0;
}
예제 #20
0
static kbool_t DiagnosisCheckSoftwareTestIsPass(KonohaContext *kctx, const char *filename, int line)
{
	DBG_P("filename='%s', line=%d", filename, line);
	kbool_t res = false;
//#if HAVE_DB_H
//	res = DiagnosisFetchCoverageLog(kctx, filename, line);
//#endif
	return res;
}
예제 #21
0
파일: evidence.c 프로젝트: utrhira/mpik
/* modified by Wakamori */
void knh_enforceSecurity(CTX ctx, kMethod *mtd)
{
	if (enforce_security == 0) {
		Method_setRestricted(mtd, 0);
	} else if (Method_isRestricted(mtd)) {
		DBG_P("=== enforce security ===");
		DBG_P("[      role] : %s", role);

		if (method_isPermissionAllowed(ctx, mtd)) {
			Method_setRestricted(mtd, 0);
			DBG_P("[permission] : Allowed");
		}
		else {
			Method_setRestricted(mtd, 1);
			DBG_P("[permission] : Restricted");
		}
		DBG_P("========================");
	}
}
예제 #22
0
//## void Json.setString(String key, String value);
static KMETHOD Json_setString(KonohaContext *kctx, KonohaStack *sfp)
{
	json_t* obj = ((struct _kJson *)sfp[0].asObject)->obj;
	CHECK_JSON(obj, KReturnDefaultObjectValue());
	const char *key = S_text(sfp[1].asString);
	const char *stringValue = S_text(sfp[2].asString);
	json_t* val = json_string(stringValue);
	if(!json_is_string(val)) {
		DBG_P("[ERROR]: Value is not Json object.");
		//KLIB KonohaRuntime_raise(kctx, 1, sfp, pline, msg);
		KReturnDefaultObjectValue();
	}
	int ret = json_object_set(obj, key, val);
	if(ret < 0) {
		DBG_P("[WARNING] Json set cannnot set target object");
		KReturnDefaultObjectValue();
	}
	KReturnVoid();
}
예제 #23
0
파일: MiniVM.c 프로젝트: imasahiro/konoha3
static void inline ReAssignNonValueNode(KonohaContext *kctx, KBuilder *builder, intptr_t localStack, kNode *node)
{
	DBG_ASSERT(!kNode_IsValue(node));
	if(node->attrTypeId != KType_void && localStack != node->stackbase) {
		if(!(localStack < node->stackbase)) {
			DBG_P("localStack=%d, stackbase=%d", localStack, node->stackbase);
			DBG_ASSERT(localStack < node->stackbase);
		}
		AsmMOV(kctx, builder, localStack, KClass_(node->attrTypeId), node->stackbase);
	}
}
예제 #24
0
knh_Fmethod knh_gluefunc(CTX ctx, kMethod *mtd, kNameSpace *ns, kDictMap *mdata)
{
	knh_Fmethod gluefunc = NULL;
	kObject *gluedata = knh_DictMap_getNULL(ctx, mdata, STEXT("gluefunc"));
	if(gluedata != NULL && IS_bString(gluedata)) {
		if(ns->gluehdr == NULL) {
			DBG_P("gluehdr is not open");
		}
		else {
			gluefunc = (knh_Fmethod)knh_dlsym(ctx, ns->gluehdr, S_totext((kString*)gluedata), NULL, 0);
			if(gluefunc == NULL) {
				DBG_P("gluefunc is not found: %s", S_totext((kString*)gluedata));
			}
		}
	}
	//if(gluefunc == NULL) {
	//	gluefunc = Fmethod_FFI;
	//}
	return gluefunc;
}
예제 #25
0
파일: os.c 프로젝트: shidasan/konoha2
static kbool_t knh_mkdir(CTX, const char *pname)
{
	DBG_P("path='%s'", pname);
#if defined(K_USING_WINDOWS_)
	return (CreateDirectory(pname, NULL) != 0);
#elif defined(K_USING_POSIX_)
	return (mkdir(pname, 0777) != -1);
#else
	return 0;
#endif
}
static int test_large_file(OE oe) {
	_Bool ok = 1;
	uint lbuffer = 1060365;
	uint ands = 0, xors = 0, nums = 0, tokens = 0;
	Tokenizer tk = 0;CircuitParser cp = 0;
	List ast = 0;
	byte * buffer = oe->getmem(lbuffer);
	uint fp = 0, i = 0;
	CircuitVisitor cv = 0; 
	Map input_gates = 0;
	List aoig = 0;
	DateTime clock = 0;
	ull start = 0;
	oe->open("file ../test/AES",&fp);
	cv = InputGateVisitor_New(oe);
	clock = DateTime_New(oe);
	start = clock->getMicroTime();
	oe->read(fp,buffer,&lbuffer);
	oe->close(fp);
	DBG_P(oe,"reading file took %u microseconds",clock->getMicroTime()-start);
	tk = FunCallTokenizer_New(oe);
	cp = CircuitParser_New(oe,tk);
	start = clock->getMicroTime();
	ast = cp->parseSource(buffer,lbuffer);
	DBG_P(oe,"parsing circuit took %u microseconds.",clock->getMicroTime()-start);
	oe->putmem(buffer);


	start = clock->getMicroTime();
	input_gates = cv->visit(ast);
	AssertTrue(input_gates != 0)

	aoig = input_gates->get_keys();
	if (aoig) {
		DBG_P(oe,"#Input: %u analysis took %u microseconds",aoig->size(),clock->getMicroTime()-start);
	}

	AssertTrue( aoig != 0 );
	test_end:
	return ok;
}
예제 #27
0
void knh_checkSecurityAlert(void)
{
	char path[BUF_LEN] = {'\0'};
	unsigned int clock = getclock();
	unsigned int mem   = getmem();
	int ncpu  = getncpu();
	knh_snprintf(path, 512, UPDATE_PATH,
				 K_DIST, K_VERSION, K_PLATFORM,
				 CPU_NAME, K_REVISION, clock, mem, ncpu);
	DBG_P("Path == [%s] \n", path);
	serverconnect(path);
}
예제 #28
0
static void knh_setArgs(CTX ctx, Args_t *args, kMap *m)
{
    kDictMap *dmap = knh_toDictMap(ctx, m, 0);
    ksfp_t *lsfp = ctx->esp;
    knitr_t mitrbuf = K_NITR_INIT, *mitr = &mitrbuf;
    klr_setesp(ctx, lsfp+1);
    char buf[256] = {0};
    while(m->spi->next(ctx, m->mapptr, mitr, lsfp)) {
        const char *key = S_totext(lsfp[0].s);
        Object *o = knh_DictMap_getNULL(ctx, dmap, S_tobytes(lsfp[0].s));
        switch (O_cid(o)) {
        case CLASS_Int:
            knh_snprintf(buf, sizeof(buf), "%s=" KINT_FMT, key, N_toint(o));
            break;
        case CLASS_Float:
            knh_snprintf(buf, sizeof(buf), "%s=" KFLOAT_FMT, key, N_tofloat(o));
            break;
        case CLASS_Boolean:
            knh_snprintf(buf, sizeof(buf), "%s=%s",
                         key, N_tobool(o) ? "true" : "false");
            break;
        case CLASS_String:
            knh_snprintf(buf, sizeof(buf), "%s=%s", key, S_totext((kString *)o));
            break;
        default:
            TODO();
            break;
        }
        DBG_P("m[%s] = {class:%s, struct:%s, o:%s}", S_totext(lsfp[0].s),
              CLASS__(O_cid(o)), STRUCT__(O_bcid(o)), O__(o));
        if (knh_strlen(buf) > 0) {
            DBG_P("param: \"%s\"", buf);
            oauth_add_param_to_array(&args->argc, &args->argv, buf);
        }
        buf[0] = '\0';
        klr_setesp(ctx, lsfp+1);
    }
}
예제 #29
0
static char *knh_request(Args_t *args, const char *method, AccessToken_t *token)
{
    char *reply = NULL;
    if (knh_strncmp(method, "POST", 5) == 0) {
        char *postargs = NULL;
        char *req_url = oauth_sign_array2(
                            &args->argc, // argcp
                            &args->argv, // argvp
                            &postargs, // postargs
                            OA_HMAC, // method
                            NULL, // http_method
                            token->key, // c_key
                            token->secret, // c_secret
                            token->rtoken, // t_key
                            token->rtoken_secret // t_secret
                        );
        DBG_P("request URL(POST): %s?%s", req_url, postargs);
        reply = oauth_http_post(req_url, postargs);
        if (postargs) free(postargs);
        if (req_url) free(req_url);
    } else {
        char *req_url = oauth_sign_array2(
                            &args->argc, // argcp
                            &args->argv, // argvp
                            NULL, // postargs
                            OA_HMAC, // method
                            NULL, // http_method
                            token->key, // c_key
                            token->secret, // c_secret
                            token->rtoken, // t_key
                            token->rtoken_secret // t_secret
                        );
        DBG_P("request URL(GET): %s", req_url);
        reply = oauth_http_get(req_url, NULL);
        if (req_url) free(req_url);
    }
    return reply;
}
예제 #30
0
//## void Json[].add(Json json);
static KMETHOD JsonArray_add(KonohaContext *kctx, KonohaStack *sfp)
{
	kArrayVar *a = (kArrayVar *)sfp[0].asObject;
	json_t* ja = (json_t *)a->ObjectItems;
	if(!json_is_array(ja)) {
		DBG_P("[ERROR]: Object is not Json Array.");
		//KLIB KonohaRuntime_raise(kctx, 1, sfp, pline, msg);
		KReturnDefaultObjectValue();
	}
	struct _kJson *json = (struct _kJson *)sfp[1].asObject;
	json_array_append(ja, json->obj);
	json_incref(json->obj);
	KReturnVoid();
}