| Line |
Branch |
Exec |
Source |
| 1 |
|
|
#ifndef __MRUBYVM_HPP__ |
| 2 |
|
|
#define __MRUBYVM_HPP__ |
| 3 |
|
|
|
| 4 |
|
|
class VM : public Module |
| 5 |
|
|
{ |
| 6 |
|
|
public: |
| 7 |
3/6
✓ Branch 1 taken 60 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 60 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 60 times.
✗ Branch 8 not taken.
|
60 |
VM() : Module(std::shared_ptr<mrb_state>(mrb_open(), mrb_close)) |
| 8 |
|
|
{ |
| 9 |
|
60 |
} |
| 10 |
|
|
|
| 11 |
|
|
VM(mrb_state* mrb) : Module(std::shared_ptr<mrb_state>(mrb, [](mrb_state*) {})) |
| 12 |
|
|
{ |
| 13 |
|
|
} |
| 14 |
|
|
|
| 15 |
|
120 |
~VM() |
| 16 |
|
120 |
{ |
| 17 |
|
120 |
} |
| 18 |
|
|
|
| 19 |
|
46 |
void run(const std::string& code) |
| 20 |
|
|
{ |
| 21 |
1/2
✓ Branch 1 taken 46 times.
✗ Branch 2 not taken.
|
46 |
std::stringstream ss; |
| 22 |
1/2
✓ Branch 1 taken 46 times.
✗ Branch 2 not taken.
|
46 |
ss << "begin;"; |
| 23 |
2/4
✓ Branch 1 taken 46 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 46 times.
✗ Branch 5 not taken.
|
46 |
ss << code << ";"; |
| 24 |
1/2
✓ Branch 1 taken 46 times.
✗ Branch 2 not taken.
|
46 |
ss << "rescue => e;"; |
| 25 |
1/2
✓ Branch 1 taken 46 times.
✗ Branch 2 not taken.
|
46 |
ss << "p e;"; |
| 26 |
1/2
✓ Branch 1 taken 46 times.
✗ Branch 2 not taken.
|
46 |
ss << "end;"; |
| 27 |
|
|
|
| 28 |
2/4
✓ Branch 1 taken 46 times.
✗ Branch 2 not taken.
✓ Branch 6 taken 46 times.
✗ Branch 7 not taken.
|
46 |
mrb_load_string(mrb.get(), ss.str().c_str()); |
| 29 |
|
46 |
} |
| 30 |
|
|
|
| 31 |
|
|
void run_file(const std::string& file) |
| 32 |
|
|
{ |
| 33 |
|
|
std::shared_ptr<mrbc_context> cxt(mrbc_context_new(mrb.get()), [=](mrbc_context* p) {mrbc_context_free(mrb.get(), p);}); |
| 34 |
|
|
mrbc_filename(mrb.get(), cxt.get(), file.c_str()); |
| 35 |
|
|
|
| 36 |
|
|
std::ifstream t(file); |
| 37 |
|
|
std::string source((std::istreambuf_iterator<char>(t)), |
| 38 |
|
|
std::istreambuf_iterator<char>()); |
| 39 |
|
|
|
| 40 |
|
|
mrb_load_nstring_cxt(mrb.get(), source.c_str(), source.length(), cxt.get()); |
| 41 |
|
|
} |
| 42 |
|
|
}; |
| 43 |
|
|
|
| 44 |
|
|
#endif // __MRUBYVM_HPP__ |
| 45 |
|
|
|