void repl_evaluate_line(Stack* context, std::string const& input, std::ostream& output) { Branch* branch = top_branch(context); int previousHead = branch->length(); parser::compile(branch, parser::statement_list, input); int newHead = branch->length(); bool anyErrors = false; int resultIndex = -1; for (int i=previousHead; i < newHead; i++) { Term* result = branch->get(i); if (has_static_error(result)) { output << "error: "; print_static_error(result, output); output << std::endl; anyErrors = true; break; } Frame* frame = top_frame(context); frame->pc = i; frame->endPc = i + 1; run_interpreter(context); if (error_occurred(context)) { output << "error: "; print_error_stack(context, std::cout); anyErrors = true; break; } resultIndex = i; } // Print results of the last expression if (!anyErrors && resultIndex != -1) { Term* result = branch->get(resultIndex); if (result->type != as_type(VOID_TYPE)) { output << find_stack_value_for_term(context, result, 0)->toString() << std::endl; } } clear_error(context); }
void test_assert_function(Term* term, int line, const char* file) { if (term == NULL) { std::cout << "NULL term in " << file << ", line " << line << std::endl; declare_current_test_failed(); return; } if (has_static_error(term)) { std::cout << "Compile error on term " << global_id(term) << std::endl; print_static_error(term, std::cout); std::cout << std::endl; std::cout << "Occurred in " << file << ", line " << line << std::endl; declare_current_test_failed(); } if (is_bool(term_value(term)) && !as_bool(term_value(term))) { std::cout << "Assertion failed: " << get_term_source_text(term) << std::endl; std::cout << "Occurred in " << file << ", line " << line << std::endl; declare_current_test_failed(); } }