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; } }
// Evaluate DNA void Parser::evaluate(const DNA& iDNA) { // Reset the quotum mInstructionCounter = 0; // Evaluate all blocks for (unsigned int i = 0; i < iDNA.genes(); i++) { // Extract the blocks unsigned char* tGene; unsigned int tSize; iDNA.extract_gene(i, tGene, tSize); // Evaluate the block evaluate_block(tGene, tSize); // Free the block free(tGene); } }
int run_debugger_repl(std::string const& filename) { Block block; load(&block, 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_block(&block, std::cout); continue; } if (input == "e") { Stack stack; evaluate_block(&stack, &block); continue; } if (input == "c") { print_static_errors_formatted(&block, std::cout); continue; } std::cout << "unrecognized command: " << input << std::endl; } return 0; }
void do_file_command(List* args, caValue* reply) { RawOutputPrefs rawOutputPrefs; bool printRaw = false; bool printSource = false; bool printState = false; bool dontRunScript = false; int argIndex = 1; while (true) { if (argIndex >= args->length()) { set_string(reply, "No filename found"); return; } if (string_eq(args->get(argIndex), "-p")) { printRaw = true; argIndex++; continue; } if (string_eq(args->get(argIndex), "-pp")) { printRaw = true; rawOutputPrefs.showProperties = true; argIndex++; continue; } if (string_eq(args->get(argIndex), "-b") || string_eq(args->get(argIndex), "-pb")) { printRaw = true; rawOutputPrefs.showBytecode = true; argIndex++; continue; } if (string_eq(args->get(argIndex), "-s")) { printSource = true; argIndex++; continue; } if (string_eq(args->get(argIndex), "-print-state")) { printState = true; argIndex++; continue; } if (string_eq(args->get(argIndex), "-n")) { dontRunScript = true; argIndex++; continue; } break; } Block block; load_script(&block, as_cstring(args->get(argIndex))); if (printSource) std::cout << get_block_source_text(&block); if (dontRunScript) return; Stack stack; evaluate_block(&stack, &block); if (printState) std::cout << to_string(&stack.state) << std::endl; if (error_occurred(&stack)) { std::cout << "Error occurred:\n"; print_error_stack(&stack, std::cout); std::cout << std::endl; return; } }