Branch* load_module(const char* module_name, Term* loadCall) { Branch* existing = find_loaded_module(module_name); if (existing != NULL) return existing; Value filename; bool found = find_module_file(module_name, &filename); if (!found) return NULL; Term* import = load_module_from_file(module_name, as_cstring(&filename))->owningTerm; // If a loadCall is provided, possibly move the new import to be before the loadCall. if (loadCall != NULL) { Term* callersModule = find_parent_term_in_branch(loadCall, import->owningBranch); if (callersModule != NULL && (import->index > callersModule->index)) move_before(import, callersModule); } // If the module has static errors, print them now. print_static_errors_formatted(nested_contents(import)); return nested_contents(import); }
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); } }
void test_assert_function(Block* block, int line, const char* file) { if (!block_check_invariants_print_result(block, std::cout)) { std::cout << "Block failed invariant check in " << file << ", line " << line << std::endl; declare_current_test_failed(); } List errors; check_for_static_errors(&errors, block); if (!errors.empty()) { std::cout << "Block has static errors at " << file << ", line " << line << std::endl; print_static_errors_formatted(&errors, std::cout); declare_current_test_failed(); } }
void test_assert_function(Block* block, int line, const char* file) { Value str; if (!block_check_invariants_print_result(block, &str)) { std::cout << as_cstring(&str) << std::endl; std::cout << "Block failed invariant check in " << file << ", line " << line << std::endl; declare_current_test_failed(); } Value errors; check_for_static_errors(&errors, block); if (!errors.isEmpty()) { std::cout << "Block has static errors at " << file << ", line " << line << std::endl; print_static_errors_formatted(&errors, &str); std::cout << as_cstring(&str) << std::endl; declare_current_test_failed(); } }
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; }
int run_debugger_repl(std::string const& filename) { Branch branch; load(&branch, filename); while (true) { std::cout << "> "; std::string input; if (!std::getline(std::cin, input)) break; if (input == "exit" || input == "/exit") break; if (input == "") continue; if (input == "p") { print_branch(std::cout, &branch); continue; } if (input == "e") { Stack stack; evaluate_branch(&stack, &branch); continue; } if (input == "c") { print_static_errors_formatted(&branch, std::cout); continue; } std::cout << "unrecognized command: " << input << std::endl; } return 0; }