static void load(Branch* branch, std::string const& filename) { if (filename == "") { clear_branch(branch); return; } load_script(branch, filename.c_str()); if (has_static_errors(branch)) print_static_errors_formatted(branch, std::cout); }
static void load(Block* block, std::string const& filename) { if (filename == "") { clear_block(block); return; } load_script(block, filename.c_str()); if (has_static_errors(block)) print_static_errors_formatted(block, std::cout); }
bool test_fail_on_static_error(Block* block) { if (has_static_errors(block)) { std::cout << "Static error in " << get_current_test_name() << std::endl; print_static_errors_formatted(block, std::cout); std::cout << std::endl; declare_current_test_failed(); return true; } return false; }
void test_block_as_assertions_list(Block* block, std::string const& contextStr) { if (has_static_errors(block)) { std::cout << "Static error " << contextStr << ":" << std::endl; print_static_errors_formatted(block, std::cout); declare_current_test_failed(); return; } std::stringstream checkInvariantsOutput; if (!block_check_invariants_print_result(block, checkInvariantsOutput)) { std::cout << "Failed invariant " << contextStr << std::endl; std::cout << checkInvariantsOutput.str() << std::endl; declare_current_test_failed(); return; } Stack context; evaluate_block(&context, block); if (context.errorOccurred) { std::cout << "Runtime error " << contextStr << std::endl; print_error_stack(&context, std::cout); declare_current_test_failed(); return; } int boolean_statements_found = 0; for (int i=0; i < block->length(); i++) { Term* term = block->get(i); if (!is_statement(term)) continue; if (!is_bool(term_value(term))) continue; boolean_statements_found++; if (!as_bool(term_value(term))) { std::cout << "Assertion failed " << contextStr << std::endl; std::cout << "failed: " << get_term_source_text(term) << std::endl; declare_current_test_failed(); return; } } if (boolean_statements_found == 0) { std::cout << "No boolean statements found " << contextStr << std::endl; declare_current_test_failed(); return; } }
void rewrite_block(Block* block, caValue* contents, caValue* reply) { clear_block(block); parser::compile(block, parser::statement_list, as_cstring(contents)); if (has_static_errors(block)) { std::stringstream errors; print_static_errors_formatted(block); set_string(reply, errors.str()); } else { set_symbol(reply, sym_Success); } }
CIRCA_EXPORT caWorld* circa_initialize() { bootstrap_kernel(); caWorld* world = global_world(); Block* builtins = global_builtins_block(); //dump(builtins); // Make sure there are no static errors in builtins. This shouldn't happen. #if 0 if (has_static_errors(builtins)) { std::cout << "Static errors found in kernel:" << std::endl; dump(builtins); Value msg; print_static_errors_formatted(builtins, &msg); dump(&msg); } #endif // Load library paths from CIRCA_LIB_PATH const char* libPathEnv = getenv("CIRCA_LIB_PATH"); if (libPathEnv != NULL) { Value libPathStr; set_string(&libPathStr, libPathEnv); Value libPaths; string_split(&libPathStr, ';', &libPaths); for (int i=0; i < list_length(&libPaths); i++) { Value* path = list_get(&libPaths, i); if (string_equals(path, "")) continue; module_add_search_path(world, as_cstring(path)); } } log_msg(0, "finished circa_initialize"); world->bootstrapStatus = s_Done; return world; }
CIRCA_EXPORT caWorld* circa_initialize() { memset(&FUNCS, 0, sizeof(FUNCS)); memset(&TYPES, 0, sizeof(TYPES)); bootstrap_kernel(); caWorld* world = global_world(); Block* kernel = global_root_block(); // Make sure there are no static errors in the kernel. This shouldn't happen. if (has_static_errors(kernel)) { std::cout << "Static errors found in kernel:" << std::endl; print_static_errors_formatted(kernel, std::cout); internal_error("circa fatal: static errors found in kernel"); } // Load library paths from CIRCA_LIB_PATH const char* libPathEnv = getenv("CIRCA_LIB_PATH"); if (libPathEnv != NULL) { Value libPathStr; set_string(&libPathStr, libPathEnv); Value libPaths; string_split(&libPathStr, ';', &libPaths); for (int i=0; i < list_length(&libPaths); i++) { caValue* path = list_get(&libPaths, i); if (string_eq(path, "")) continue; module_add_search_path(world, as_cstring(path)); } } log_msg(0, "finished circa_initialize"); world->bootstrapStatus = sym_Done; return world; }