Example #1
0
static void dumpMethod(CTX, ksfp_t *sfp, kMethod *mtd)
{
	kwb_t wb;
	kwb_init(&(_ctx->stack->cwb), &wb);
	KSETv(sfp[2].mtd, mtd);
	O_ct(mtd)->p(_ctx, sfp, 2, &wb, 1);
	PLAT printf_i("%s\n", kwb_top(&wb, 1));
	kwb_free(&wb);
	return;
}
Example #2
0
void knh_Iterator_close(CTX, kIterator *it)
{
	DBG_ASSERT(IS_bIterator(it));
	if(it->fnext_1 != Fitrnext_end) {
		KSETv(DP(it)->source, K_NULL);
		if(DP(it)->m.nfree != NULL) {
			if(DP(it)->m.nptr != NULL) {
				DP(it)->m.nfree(DP(it)->m.nptr);
			}
			DP(it)->m.nfree = NULL;
		}
		DP(it)->m.nptr = NULL;
		it->fnext_1   = Fitrnext_end;
	}
}
Example #3
0
static void Method_threadCode(KonohaContext *kctx, kMethod *mtd, kByteCode *kcode)
{
	kMethodVar *Wmtd = (kMethodVar*)mtd;
	KLIB kMethod_setFunc(kctx, mtd, MethodFunc_runVirtualMachine);
	KSETv(Wmtd, Wmtd->kcode, kcode);
	Wmtd->pc_start = KonohaVirtualMachine_run(kctx, kctx->esp + 1, kcode->code);
	if(verbose_code) {
		DBG_P("DUMP CODE");
		VirtualMachineInstruction *pc = mtd->pc_start;
		while(1) {
			dumpOPCODE(kctx, pc, mtd->pc_start);
			if (pc->opcode == OPCODE_RET) {
				break;
			}
			pc++;
		}
	}
}
Example #4
0
kPath* new_CurrentPath(CTX)
{
	char buf[K_PATHMAX];
#if defined(K_USING_WINDOWS_)
	char *ptr = _fullpath(buf, ".", K_PATHMAX);
#elif defined(K_USING_POSIX_)
	char *ptr = realpath(".", buf);
#else
	char *ptr = NULL;
	buf[0] = '.'; buf[1] = 0;
#endif
	kPath *pth = new_(Path);
	KSETv(pth->urn, new_kString(buf, knh_strlen(buf), SPOL_POOL));
	pth->ospath = S_text(pth->urn);
	if(ptr != buf && ptr != NULL) {
		free(ptr);
	}
	kObjectoNULL(_ctx, pth);
	return pth;
}
Example #5
0
void knh_System_initPath(CTX)
{
	CWB_t cwbbuf, *cwb = CWB_open(_ctx, &cwbbuf);
	kDictMap *sysprops = ctx->share->props;
	kbytes_t home = {{NULL}, 0}, user = {{NULL}, 0};

	// current working directory
	knh_buff_addospath(_ctx, cwb->ba, cwb->pos, 0, STEXT("."));
	KSETv(ctx->share->rootks->path, new_Path(_ctx, knh_buff_newRealPathString(_ctx, cwb->ba, cwb->pos)));

	home.text = (const char*)knh_getenv("KONOHAHOME");
#if defined(K_KONOHAHOME)
	if(home.text == NULL) {
		home.text = K_KONOHAHOME;
	}
#endif
	if(home.text != NULL) {
		home.len = knh_strlen(home.text);
		SETPROP("konoha.home.path", new_T(home.text));
	}
#if defined(K_USING_WINDOWS_)
	{
		char buf[K_PATHMAX];
		int bufsiz = K_PATHMAX;
		HMODULE h = LoadLibrary(NULL);
		GetModuleshortnameA(h, buf, bufsiz);
		CWB_clear(cwb, 0);
		knh_buff_addospath(_ctx, cwb->ba, cwb->pos, 0, B(buf));
		SETPROP("konoha.bin.path", knh_buff_newRealPathString(_ctx, cwb->ba, cwb->pos));
		if(home.text == NULL) {
			kString *s;
			CWB_clear(cwb, 0);
			knh_buff_addpath(_ctx, cwb->ba, cwb->pos, 0, B(buf));
			knh_buff_trim(_ctx, cwb->ba, cwb->pos, '\\');
			knh_buff_trim(_ctx, cwb->ba, cwb->pos, '\\');
			knh_buff_addospath(_ctx, cwb->ba, cwb->pos, 1/*isSep*/, STEXT("konoha"));
			s = CWB_newString(_ctx, cwb, 0);
			SETPROP("konoha.home.path", s);
			home = S_tobytes(s);
		}
	}
#elif defined(K_USING_LINUX_)
	// @url(http://shinh.skr.jp/binary/b2con.html)
	// http://doc.trolltech.com/3.3/qapplication.html#applicationDirPath
	{
		char buf[K_PATHMAX];
		int bufsiz = K_PATHMAX;
		ssize_t size = readlink("/proc/self/exe", buf, bufsiz);
		CWB_clear(cwb, 0);
		knh_buff_addospath(_ctx, cwb->ba, cwb->pos, 0, new_bytes2(buf, size));
		SETPROP("konoha.bin.path", knh_buff_newRealPathString(_ctx, cwb->ba, cwb->pos));
		if(home.text == NULL) {
			kString *s;
			CWB_clear(cwb, 0);
			knh_buff_addpath(_ctx, cwb->ba, cwb->pos, 0, new_bytes2(buf, size));
			knh_buff_trim(_ctx, cwb->ba, cwb->pos, '/');
			knh_buff_trim(_ctx, cwb->ba, cwb->pos, '/');
			knh_buff_addpath(_ctx, cwb->ba, cwb->pos, 1/*isSep*/, STEXT("konoha"));
			s = CWB_newString(_ctx, cwb, 0);
			SETPROP("konoha.home.path", s);
			home = S_tobytes(s);
		}
	}
#elif defined(K_USING_MACOSX_)
	{
		kString *binpath;
		CWB_clear(cwb, 0);
		knh_buff_addospath(_ctx, cwb->ba, cwb->pos, 0, B(_dyld_get_image_name(0)));
		binpath = knh_buff_newRealPathString(_ctx, cwb->ba, cwb->pos);
		SETPROP("konoha.bin.path", binpath);
		if(home.text == NULL) {
			CWB_clear(cwb, 0);
			knh_buff_addpath(_ctx, cwb->ba, cwb->pos, 0, S_tobytes(binpath));
			knh_buff_trim(_ctx, cwb->ba, cwb->pos, '/');
			knh_buff_trim(_ctx, cwb->ba, cwb->pos, '/');
			knh_buff_addpath(_ctx, cwb->ba, cwb->pos, 1/*isSep*/, STEXT("konoha"));
			kString *s = CWB_newString(_ctx, cwb, 0);
			SETPROP("konoha.home.path", s);
			home = S_tobytes(s);
		}
	}
#else
	home = STEXT("/opt/konoha");
	SETPROP("konoha.home.path", new_T("/opt/konoha"));
#endif
	DBG_ASSERT(home.utext != NULL);

	/* $konoha.package.path {$konoha.home.path}/package */
	CWB_clear(cwb, 0);
	knh_buff_addpath(_ctx, cwb->ba, cwb->pos, 0, home);
	knh_buff_addpath(_ctx, cwb->ba, cwb->pos, 1/*sep*/, STEXT("package"));
	knh_buff_addpath(_ctx, cwb->ba, cwb->pos, 1/*sep*/, STEXT(LIBK_VERSION));
	SETPROP("konoha.package.path", CWB_newString(_ctx, cwb, 0));

	/* $konoha.script.path {$konoha.home.path}/script */
	knh_buff_addpath(_ctx, cwb->ba, cwb->pos, 0, home);
	knh_buff_addpath(_ctx, cwb->ba, cwb->pos, 1/*sep*/, STEXT("script"));
	knh_buff_addpath(_ctx, cwb->ba, cwb->pos, 1/*sep*/, STEXT(LIBK_VERSION));
	SETPROP("konoha.script.path", CWB_newString(_ctx, cwb, 0));

#if defined(K_USING_WINDOWS_)
	user.text = knh_getenv("USERPROFILE");
#else
	user.text = knh_getenv("HOME");
#endif
	if(user.text != NULL) {
		/* $user.path */
		user.len = knh_strlen(user.text);
		knh_buff_addpath(_ctx, cwb->ba, cwb->pos, 0, user);
		knh_buff_addpath(_ctx, cwb->ba, cwb->pos, 1, STEXT(K_KONOHAFOLDER));
		SETPROP("user.path", CWB_newString(_ctx, cwb, 0));
		knh_buff_addospath(_ctx, cwb->ba, cwb->pos, 0, user);
		knh_buff_addospath(_ctx, cwb->ba, cwb->pos, 1, STEXT(K_KONOHAFOLDER));
		knh_buff_mkdir(_ctx, cwb->ba, cwb->pos);
		CWB_clear(cwb, 0);
		knh_buff_addospath(_ctx, cwb->ba, cwb->pos, 0, user);
		knh_buff_addospath(_ctx, cwb->ba, cwb->pos, 1/*sep*/, STEXT(K_KONOHAFOLDER));
		knh_buff_addospath(_ctx, cwb->ba, cwb->pos, 1/*sep*/, STEXT("package"));
		knh_buff_addospath(_ctx, cwb->ba, cwb->pos, 1/*sep*/, STEXT(LIBK_VERSION));
		SETPROP("user.package.path", CWB_newString(_ctx, cwb, 0));
	}
	CWB_close(_ctx, cwb);
}
Example #6
0
static int parseNumber(KonohaContext *kctx, kTokenVar *tk, TokenizerEnv *tenv, int tok_start)
{
	const char *start = tenv->source + tok_start, *end, *ts = start;
	int c = *ts++;
	if (!(c == '.' || ('0' <= c && c <= '9'))) {
		/* It do not seem as Number */
		return tok_start;
	}
	int isFloat = 0;
	/*
	 * DIGIT  = 0-9
	 * DIGITS = DIGIT | DIGIT DIGITS
	 * INT    = DIGIT | DIGIT1-9 DIGITS
	 * FLOAT  = INT
	 *        | INT FRAC
	 *        | INT EXP
	 *        | INT FRAC EXP
	 * FRAC   = "." digits
	 * EXP    = E digits
	 * E      = 'e' | 'e+' | 'e-' | 'E' | 'E+' | 'E-'
	 */
	if (c == '0') {
		c = *ts++;
	}
	else if ('1' <= c && c <= '9') {
		for (; '0' <= c && c <= '9' && c != 0; c = *ts++) {
			if (c == '_') continue;
		}
	}
	if (c != '.' && c != 'e' && c != 'E') {
		goto L_emit;
	}
	if (c == '.') {
		isFloat = 1;
		for (c = *ts++; '0' <= c && c <= '9' && c != 0; c = *ts++) {
			if (c == '_') continue;
		}
	}
	if (c == 'e' || c == 'E') {
		isFloat = 1;
		c = *ts++;
		if (!('0' <= c && c <= '9') && !(c == '+' || c == '-')) {
			ts--;
			goto L_emit;
		}
		if (c == '+' || c == '-') {
			c = *ts++;
		}
		for (; '0' <= c && c <= '9' && c != 0; c = *ts++) {
			if (c == '_') continue;
		}
	}
	L_emit:;
	end = ts;
	if (IS_NOTNULL(tk)) {
		/* skip unit */
		while (isalpha(*ts) && *ts != 0)
			ts++;
		KSETv(tk, tk->text, KLIB new_kString(kctx, start, end - start - 1, SPOL_ASCII));
		tk->unresolvedTokenType = (isFloat)? TokenType_FLOAT : TokenType_INT;
	}
	return tok_start + ts - start - 1;
}