コード例 #1
0
ファイル: runtime.c プロジェクト: utrhira/mpik
static void knh_shell(CTX ctx)
{
	void *shell_status = NULL;
	BEGIN_LOCAL(ctx, lsfp, 2);
//	LOCAL_NEW(ctx, lsfp, 0, kInputStream *, bin, new_BytesInputStream(ctx, new_Bytes(ctx, "shell", K_PAGESIZE)));
	{
		CWB_t cwbbuf, *cwb = CWB_open(ctx, &cwbbuf);
		knh_showWelcome(ctx, cwb->w);
		knh_showSecurityAlert(ctx, cwb->w);
		shell_status = shell_init(ctx, CWB_totext(ctx, cwb), NULL);
		CWB_close(ctx, cwb);
	}
	while(1) {
		{
			CWB_t cwbbuf, *cwb = CWB_open(ctx, &cwbbuf);
			kstatus_t status = readstmt(ctx, cwb);
			if(status == K_BREAK) {
				CWB_close(ctx, cwb);
				break;
			}
			if(CWB_size(cwb) == 0) {
				CWB_close(ctx, cwb);
				continue;
			}
			status = shell_command(ctx, CWB_totext(ctx, cwb));
			if(status == K_BREAK) {
				CWB_close(ctx, cwb);
				break;
			}
			if(status == K_REDO) {
				CWB_close(ctx, cwb);
				continue;
			}
#ifdef K_USING_SUGAR
			kString *script = CWB_newString(ctx, cwb, 0);
			KNH_SETv(ctx, lsfp[0].o, script);
			knh_beval2(ctx, S_totext(script), 1);
#else
			kInputStream *bin = new_BytesInputStream(ctx, CWB_totext(ctx, cwb), CWB_size(cwb));
			KNH_SETv(ctx, lsfp[0].o, bin);
			knh_beval(ctx, bin, 1);
#endif
		}
		knh_OutputStream_flush(ctx, ctx->out);
		if(ctx->isEvaled == 1) {
			CWB_t cwbbuf, *cwb = CWB_open(ctx, &cwbbuf);
			knh_write_Object(ctx, cwb->w, ctx->evaled, FMT_dump);
			knh_showSecurityAlert(ctx, cwb->w);
			if(CWB_size(cwb) !=0) {
				shell_display(ctx, shell_status, CWB_totext(ctx, cwb));
			}
			CWB_close(ctx, cwb);
			WCTX(ctx)->isEvaled = 0;
		}
	}
	shell_cleanup(ctx, shell_status);
	END_LOCAL(ctx, lsfp);
}
コード例 #2
0
ファイル: evidence.c プロジェクト: utrhira/mpik
void THROW_ParamTypeError(CTX ctx, ksfp_t *sfp, size_t n, kmethodn_t mn, kclass_t reqt, kclass_t cid)
{
	CWB_t cwbbuf, *cwb = CWB_open(ctx, &cwbbuf);
	char msg[256], mname[256];
	knh_printf(ctx, cwb->w, "Script!!: Type Error: %T.%M(#%d)", cid, mn, (int)n);
	knh_snprintf(msg, sizeof(msg), "%s", CWB_totext(ctx, cwb));
	CWB_close(ctx, cwb);
	knh_printf(ctx, cwb->w, "%C.%M", cid, mn);
	knh_snprintf(mname, sizeof(mname), "%s", CWB_totext(ctx, cwb));
	CWB_close(ctx, cwb);
	KNH_NTHROW2(ctx, sfp, msg, "konoha:type", K_FAILED, KNH_LDATA(LOG_msg(msg), LOG_s("method", mname), LOG_i("argument", n), LOG_t("requested_type", reqt), LOG_t("given_type", cid)));
}
コード例 #3
0
ファイル: evidence.c プロジェクト: utrhira/mpik
void THROW_NoSuchMethod(CTX ctx, ksfp_t *sfp, kclass_t cid, kmethodn_t mn)
{
	CWB_t cwbbuf, *cwb = CWB_open(ctx, &cwbbuf);
	char msg[256], mname[256];
	knh_printf(ctx, cwb->w, "Script!!: No Such Method: %T.%M", cid, mn);
	knh_snprintf(msg, sizeof(msg), "%s", CWB_totext(ctx, cwb));
	CWB_close(ctx, cwb);
	knh_printf(ctx, cwb->w, "%C.%M", cid, mn);
	knh_snprintf(mname, sizeof(mname), "%s", CWB_totext(ctx, cwb));
	CWB_close(ctx, cwb);
	KNH_NTHROW2(ctx, sfp, msg, "konoha:type", K_FAILED, KNH_LDATA(LOG_msg(msg), LOG_s("method", mname)));
}
コード例 #4
0
ファイル: runtime.c プロジェクト: utrhira/mpik
static kstatus_t readstmt(CTX ctx, CWB_t *cwb)
{
	int line = 1;
	kstatus_t status = K_CONTINUE;
	CWB_clear(cwb, 0);
	fputs(TERM_BBOLD(ctx), stdout);
	while(1) {
		int check;
		char *ln = ctx->spi->readline(line == 1 ? ">>> " : "    ");
		if(ln == NULL) {
			CWB_clear(cwb, 0);
			status = K_BREAK;
			break;
		}
		if(line > 1) knh_Bytes_putc(ctx, cwb->ba, '\n');
		knh_Bytes_write(ctx, cwb->ba, B(ln));
		free(ln);
		if((check = shell_checkstmt(CWB_tobytes(cwb))) > 0) {
			line++;
			continue;
		}
		if(check < 0) {
			fputs("(Cancelled)...\n", stdout);
			CWB_clear(cwb, 0);
		}
		break;
	}
	if(CWB_size(cwb) > 0) {
		const char *p = CWB_totext(ctx, cwb);
		ctx->spi->add_history(p);
	}
	fputs(TERM_EBOLD(ctx), stdout);
	fflush(stdout);
	return status;
}
コード例 #5
0
ファイル: system.c プロジェクト: shidasan/konoha2
kString* knh_getPropertyNULL(CTX, kbytes_t key)
{
	if(knh_bytes_startsWith_(key, STEXT("env."))) {
		CWB_t cwbbuf, *cwb = CWB_open(_ctx, &cwbbuf);
		CWB_nzenvkey(_ctx, cwb, knh_bytes_last(key, 4));
		char *v = knh_getenv(CWB_totext(_ctx, cwb));
		CWB_close(_ctx, cwb);
		if(v == NULL) return NULL;
		return new_kString(v, knh_strlen(v), SPOL_ASCII|SPOL_POOL);
	}
	return (kString*)knh_DictMap_getNULL(_ctx,  ctx->share->props, key);
}
コード例 #6
0
ファイル: konohac.c プロジェクト: OkamotoYuki/konohascript
static void load_codegenerator(CTX ctx)
{
    KONOHA_BEGIN(ctx);
    CompilerAPI_disable(ctx);
    if (codegenerator_file[compile_mode]) {
        kbytes_t t = new_bytes((char*)codegenerator_file[compile_mode]);
        knh_loadPackage(ctx, t);
        CWB_t cwbbuf, *cwb = CWB_open(ctx, &cwbbuf);
        kString *s = (kString *) knh_DictMap_getNULL(ctx, ctx->share->props, STEXT("konoha.package.path"));
        CWB_clear(cwb, 0);
        knh_buff_addpath(ctx, cwb->ba, cwb->pos, 0, S_tobytes(s));
        knh_buff_addpath(ctx, cwb->ba, cwb->pos, 1, STEXT("konoha.compiler"));
        knh_buff_addpath(ctx, cwb->ba, cwb->pos, 1, STEXT("compiler"));
        knh_buff_addpath(ctx, cwb->ba, cwb->pos, 0, STEXT(K_OSDLLEXT));
        void *p = knh_dlopen(ctx, CWB_totext(ctx, cwb));
        typedef void (*knh_Fpkgcomplete)(CTX);
        knh_Fpkgcomplete pkgcomplete = (knh_Fpkgcomplete) knh_dlsym(ctx, p, "reset_compiler_api", NULL, 1);
        if (pkgcomplete) pkgcomplete(ctx);
        CWB_close(ctx, cwb);
    }
    CompilerAPI_enable(ctx);
    KONOHA_END(ctx);
}