示例#1
0
int main(int argc, const char *argv[])
{
    klib2_t *lib;
    static kplatform_t plat = {
    	"test", 4096,
    };
    konoha_t konoha = konoha_open((const kplatform_t*)&plat);
    lib = konoha->lib2;
    int i;
    void *malloced[100];
    for (i = 0; i < 100; ++i) {
        malloced[i] = lib->Kmalloc(0, i);
    }
    for (i = 0; i < 100; ++i) {
        lib->Kfree(0, malloced[i], i);
    }
    MODGC_check_malloced_size();
    for (i = 0; i < 100; ++i) {
        malloced[i] = lib->Kzmalloc(0, i);
        int j;
        char *p = malloced[i];
        for (j = 0; j < i; ++j) {
            assert(p[0] == 0);
        }
    }
    for (i = 0; i < 100; ++i) {
        lib->Kfree(0, malloced[i], i);
    }
    konoha_close(konoha);
    MODGC_check_malloced_size();
    return 0;
}
示例#2
0
int main(int argc, char *argv[])
{
	kbool_t ret = 1;
	int scriptidx = konoha_ginit(argc, argv);
	if(builtin_test != NULL) {
		return konoha_builtintest(builtin_test);
	}
	if(test_script != NULL) {
		return konoha_test(test_script);
	}
	konoha_t konoha = konoha_open();
	if(preimport != NULL) {
		konoha_preimport((CTX_t)konoha, preimport);
	}
	if(startup_script != NULL) {
		konoha_startup(konoha, startup_script);
	}
	if(scriptidx < argc) {
		ret = konoha_load(konoha, argv[scriptidx]);
	}
	if(ret && interactive_flag) {
		ret = konoha_shell(konoha);
	}
	konoha_close(konoha);
	MODGC_check_malloced_size();
	return ret ? konoha_AssertResult: 1;
}
示例#3
0
int main(int argc, const char *argv[])
{
    static kplatform_t plat = {
    	"test", 4096,
    };
    konoha_t konoha = konoha_open((const kplatform_t*)&plat);
    test_module_load(konoha);
    test_classdef_load(konoha);
    test_mtd_load(konoha);
    konoha_close(konoha);
    MODGC_check_malloced_size();
    return 0;
}
示例#4
0
int main(int argc, const char *argv[])
{
    static kplatform_t plat = {
    	"test", 4096,
    };
    konoha_t konoha = konoha_open((const kplatform_t*)&plat);
    int i;
    for (i = 0; i < 100; ++i) {
        test_Kwb(konoha);
    }
    konoha_close(konoha);
    MODGC_check_malloced_size();
    return 0;
}
示例#5
0
int main(int argc, char *argv[])
{
	kbool_t ret = 1;
	if(getenv("KONOHA_DEBUG") != NULL) {
		verbose_debug = 1;
		verbose_gc = 1;
		verbose_sugar = 1;
		verbose_code = 1;
	}
	kplatform_t *plat = platform_shell();
	konoha_t konoha = konoha_open((const kplatform_t*)plat);
	ret = konoha_parseopt(konoha, plat, argc, argv);
	konoha_close(konoha);
	MODGC_check_malloced_size();
	return ret ? konoha_AssertResult: 0;
}
示例#6
0
static int konoha_builtintest(const char* name)
{
#ifdef USE_BUILTINTEST
	Ftest f = lookupTestFunc(KonohaTestSet, name);
	if(f != NULL) {
		konoha_t konoha = konoha_open();
		int ret = f((CTX_t)konoha);
		konoha_close(konoha);
		return ret;
	}
	fprintf(stderr, "Built-in test is not found: '%s'\n", name);
#else
	fprintf(stderr, "Built-in tests are not built; rebuild with -DUSE_BUILTINTEST\n");
#endif
	return 1;
}
示例#7
0
int main(int argc, const char *argv[])
{
    int i, argc_ = argc;
    const char *argv_[argc_];
    const char *fname = parse_option(&argc_, argv, argv_);
    if (fname == NULL) {
        fprintf(stderr, "%s [--emit-llvm/--emit-js] file\n", argv[0]);
        return 1;
    }
    konoha_t konoha = konoha_open();
    CTX ctx = konoha;
    kString *s = new_T(fname);
    knh_DictMap_set(ctx, ctx->share->props, new_T("script.name"), s);

    kArray *a = new_Array(ctx, CLASS_String, argc_);
    for(i = 2; i < argc_; i++) {
        knh_Array_add(ctx, a, new_String2(ctx, CLASS_String, argv_[i],
                    knh_strlen(argv_[i]), SPOL_TEXT|SPOL_POOLALWAYS));
    }
    knh_DictMap_set(ctx, ctx->share->props, new_T("script.argv"), a);

    kbytes_t t = knh_bytes_nsname(S_tobytes(s));
    knh_Script_setNSName(ctx, ctx->script, new_S(t.text, t.len));
    kbytes_t pkgname = STEXT("konoha.compiler");
    knh_loadPackage(ctx, pkgname);

    load_codegenerator(ctx);
    if (!compiler_run_main) {
        knh_setCompileMode(ctx, 1);
    }
    knh_startScript(ctx, (const char*)fname);

    /* CompilerAPI->dump() */
    kMethod *mtd = load_method(ctx,
            O_cid(ctx->share->konoha_compiler), STEXT("dump"));
    BEGIN_LOCAL(ctx, lsfp, K_CALLDELTA+1); {
        KNH_SETv(ctx, lsfp[K_CALLDELTA].o, ctx->share->konoha_compiler);
        KNH_SCALL(ctx, lsfp, 0, mtd, 0);
    } END_LOCAL(ctx, lsfp);
    if (compiler_run_main) {
        knh_stack_clear(ctx, ctx->stack);
        knh_runMain(ctx, argc_, argv_);
    }
    konoha_close(konoha);
    return 0;
}
示例#8
0
static int konoha_test(const char *testname)
{
	verbose_debug = 0;
	verbose_sugar = 0;
	verbose_gc    = 0;
	verbose_code  = 0;
	konoha_t konoha = konoha_open();
	if(preimport != NULL) {
		konoha_preimport((CTX_t)konoha, preimport);
	}
	if(startup_script != NULL) {
		konoha_startup(konoha, startup_script);
	}
	int ret = 0;//OK
	char script_file[256];
	char correct_file[256];
	char result_file[256];
	snprintf(script_file, 256, "%s", testname);
	snprintf(correct_file, 256, "%s.proof", script_file);
	snprintf(result_file, 256, "%s.tested", script_file);
	FILE *fp = fopen(correct_file, "r");
	if (fp == NULL) {
		fprintf(stdout, "no proof file: %s\n", testname);
	}
	stdlog = fopen(result_file, "w");
	((struct _klib2*)konoha->lib2)->Kreport  = Kreport;
	((struct _klib2*)konoha->lib2)->Kreportf = Kreportf;
	konoha_load(konoha, script_file);
	fprintf(stdlog, "Q.E.D.\n");   // Q.E.D.
	fclose(stdlog);
	if(fp != NULL) {
		FILE *fp2 = fopen(result_file, "r");
		ret = check_result(fp, fp2);
		if(ret == 0) {
			fprintf(stdout, "[PASS]: %s\n", testname);
		}
		fclose(fp);
		fclose(fp2);
	}
	else {
		ret = 1;
	}
	konoha_close(konoha);
	return ret;
}
示例#9
0
int main(int argc, const char *argv[])
{
	MPI_Init(&argc, (char***)&argv);
	konoha_ginit(argc, argv);
	konoha_t konoha = konoha_open();
	int _world_rank;
	MPI_Comm_rank(MPI_COMM_WORLD, &_world_rank);
#ifdef KNH_MPI_PROFILE
	double _begin = MPI_Wtime();
#endif
	konoha_main(konoha, argc, argv);
#ifdef KNH_MPI_PROFILE
	double _finish = MPI_Wtime();
	double _duration = _finish - _begin;
	{
		CTX ctx = (CTX)konoha;
		KNH_NTRACE2(ctx, "konoha_main(MPI)", K_NOTICE,
					KNH_LDATA(LOG_f("begin", _begin), LOG_f("finish", _finish), LOG_f("duration", _duration), LOG_i("myrank", _world_rank)));
	}
#endif
	konoha_close(konoha);
	MPI_Finalize();
	return 0;
}