ast_result_t pass_scope(ast_t** astp, pass_opt_t* options) { typecheck_t* t = &options->check; ast_t* ast = *astp; switch(ast_id(ast)) { case TK_USE: return use_command(ast, options); case TK_TYPE: case TK_INTERFACE: case TK_TRAIT: case TK_PRIMITIVE: case TK_CLASS: case TK_ACTOR: return scope_entity(t, ast); case TK_FFIDECL: if(!set_scope(t, t->frame->package, ast_child(ast), ast)) return AST_ERROR; break; case TK_PARAM: if(!set_scope(t, ast, ast_child(ast), ast)) return AST_ERROR; break; case TK_TYPEPARAM: if(!set_scope(t, ast, ast_child(ast), ast)) return AST_ERROR; break; case TK_LET: case TK_VAR: if(!scope_local(t, ast)) return AST_ERROR; break; default: {} } return AST_OK; }
static bool scope_method(typecheck_t* t, ast_t* ast) { ast_t* id = ast_childidx(ast, 1); if(!set_scope(t, ast_parent(ast), id, ast)) return false; if(ast_id(ast) == TK_NEW) set_fields_undefined(ast); return true; }
static ast_result_t scope_entity(typecheck_t* t, ast_t* ast) { AST_GET_CHILDREN(ast, id, typeparams, cap, provides, members); if(!set_scope(t, t->frame->package, id, ast)) return AST_ERROR; // Scope fields and methods immediately, so that the contents of method // signatures and bodies cannot shadow fields and methods. ast_t* member = ast_child(members); while(member != NULL) { switch(ast_id(member)) { case TK_FVAR: case TK_FLET: case TK_EMBED: if(!set_scope(t, member, ast_child(member), member)) return AST_ERROR; break; case TK_NEW: case TK_BE: case TK_FUN: if(!scope_method(t, member)) return AST_ERROR; break; default: assert(0); return AST_FATAL; } member = ast_sibling(member); } return AST_OK; }
int32_t main() { uint32_t total_num = 0, error_num = 0; set_scope("No transpose test"); ++total_num; if (0 != no_transpose()) { TEST_ERR_OUTPUT("Test failed."); ++error_num; } else { TEST_SUCC_OUTPUT("Test succeed."); } printf("%sTest finished. TOTAL: %d, SUCCEED: %d, FAILED: %d%s\n", CYN, total_num, total_num - error_num, error_num, RESET); return 0; }
bool use_package(ast_t* ast, const char* path, ast_t* name, pass_opt_t* options) { assert(ast != NULL); assert(path != NULL); ast_t* package = package_load(ast, path, options); if(package == NULL) { ast_error(ast, "can't load package '%s'", path); return false; } if(name != NULL && ast_id(name) == TK_ID) // We have an alias return set_scope(NULL, ast, name, package); // Store the package so we can import it later without having to look it up // again ast_setdata(ast, (void*)package); return true; }
static bool scope_local(typecheck_t* t, ast_t* ast) { // Local resolves to itself ast_t* id = ast_child(ast); return set_scope(t, ast_parent(ast), id, id); }
int32_t main() { uint32_t total_num = 0, error_num = 0; set_scope("CUDA test"); int32_t lda[] = { LDA_0, LDA_1, LDA_2 }; int32_t ldb[] = { LDB_0, LDB_1, LDB_2 }; TEST_INFO_OUTPUT("float + TB_128."); ++total_num; if (0 != cuda_test(TTC_TYPE_S, TTC_TB_128, lda, ldb)) { TEST_ERR_OUTPUT("TYPE_S + TB_128 failed."); ++error_num; } else { TEST_SUCC_OUTPUT("TYPE_S + TB_128 succeed."); } TEST_INFO_OUTPUT("TYPE_S + TB_128. (NULL lda ldb test)"); ++total_num; if (0 == cuda_test(TTC_TYPE_S, TTC_TB_128, NULL, NULL)) { TEST_ERR_OUTPUT("TYPE_S + TB_128 failed. " "Library should complain null lda and ldb."); ++error_num; } else { TEST_SUCC_OUTPUT("TYPE_S + TB_128 succeed. " "Library complained null lda and ldb."); } TEST_INFO_OUTPUT("TYPE_D + TB_128."); ++total_num; if (0 != cuda_test(TTC_TYPE_D, TTC_TB_128, lda, ldb)) { TEST_ERR_OUTPUT("TYPE_D + TB_128 failed."); ++error_num; } else { TEST_SUCC_OUTPUT("TYPE_D + TB_128 succeed."); } TEST_INFO_OUTPUT("TYPE_DS + TB_256."); ++total_num; if (0 != cuda_test(TTC_TYPE_DS, TTC_TB_256, lda, ldb)) { TEST_ERR_OUTPUT("TYPE_DS + TB_256 failed."); ++error_num; } else { TEST_SUCC_OUTPUT("TYPE_DS + TB_256 succeed."); } TEST_INFO_OUTPUT("TYPE_ZC + TB_512."); ++total_num; if (0 != cuda_test(TTC_TYPE_ZC, TTC_TB_512, lda, ldb)) { TEST_ERR_OUTPUT("TYPE_ZC + TB_512 failed."); ++error_num; } else { TEST_SUCC_OUTPUT("TYPE_ZC + TB_512 succeed."); } set_scope("No beta test"); TEST_INFO_OUTPUT("TYPE_DS + CUDA + DEF."); ++total_num; if (0 != no_beta_test(TTC_TYPE_DS, TTC_ARCH_CUDA, TTC_CMP_DEFAULT)) { TEST_ERR_OUTPUT("TYPE_DS + CUDA + DEF failed."); ++error_num; } else { TEST_SUCC_OUTPUT("TYPE_DS + CUDA + DEF succeed."); } TEST_INFO_OUTPUT("TYPE_Z + CUDA + DEF."); ++total_num; if (0 != no_beta_test(TTC_TYPE_Z, TTC_ARCH_CUDA, TTC_CMP_DEFAULT)) { TEST_ERR_OUTPUT("TYPE_Z + CUDA + DEF failed."); ++error_num; } else { TEST_SUCC_OUTPUT("TYPE_Z + CUDA + DEF succeed."); } TEST_INFO_OUTPUT("TYPE_CZ + CUDA + DEF."); ++total_num; if (0 != no_beta_test(TTC_TYPE_CZ, TTC_ARCH_CUDA, TTC_CMP_DEFAULT)) { TEST_ERR_OUTPUT("TYPE_CZ + CUDA + DEF failed."); ++error_num; } else { TEST_SUCC_OUTPUT("TYPE_CZ + CUDA + DEF succeed."); } printf("%sTest finished. TOTAL: %d, SUCCEED: %d, FAILED: %d%s\n", CYN, total_num, total_num - error_num, error_num, RESET); return 0; }