| 60 | } |
| 61 | |
| 62 | void Program::parse_with_error(string filename) |
| 63 | { |
| 64 | name = boost::filesystem::path(filename).stem().string(); |
| 65 | ifstream pinp(filename); |
| 66 | if (pinp.fail()) |
| 67 | throw file_error(filename); |
| 68 | |
| 69 | try |
| 70 | { |
| 71 | parse(pinp); |
| 72 | } |
| 73 | catch (bytecode_error& e) |
| 74 | { |
| 75 | stringstream os; |
| 76 | os << "Cannot parse " << filename << " (" << e.what() << ")" << endl; |
| 77 | os << "Does the compiler version match the virtual machine? " |
| 78 | << "If in doubt, recompile the VM"; |
| 79 | if (not OnlineOptions::singleton.executable.empty()) |
| 80 | os << " using 'make " << OnlineOptions::singleton.executable << "'"; |
| 81 | os << "."; |
| 82 | throw bytecode_error(os.str()); |
| 83 | } |
| 84 | |
| 85 | // compute hash |
| 86 | pinp.clear(); |
| 87 | pinp.seekg(0); |
| 88 | Hash hasher; |
| 89 | while (pinp.peek(), !pinp.eof()) |
| 90 | { |
| 91 | char buf[1024]; |
| 92 | size_t n = pinp.readsome(buf, 1024); |
| 93 | hasher.update(buf, n); |
| 94 | } |
| 95 | hash = hasher.final().str(); |
| 96 | } |
| 97 | |
| 98 | void Program::parse(istream& s) |
| 99 | { |