File tree 2 files changed +30
-8
lines changed
2 files changed +30
-8
lines changed Original file line number Diff line number Diff line change 1
1
#include " include/StackVM.h"
2
+ #include < iostream>
3
+ #include < fstream>
2
4
3
- int main (){
4
- vm::StackVM vm;
5
+
6
+ int main (int argc, char *argv[]){
7
+ if (argc <=1 ){
8
+ std::cout<<" no file input." <<std::endl;
9
+ return 0 ;
10
+ }
11
+
12
+ std::ifstream binFile;
13
+ binFile.open (argv[1 ], std::ios::binary | std::ios::in);
14
+ if (!binFile){
15
+ std::cout<<" can not open file " <<argv[1 ]<<std::endl;
16
+ }
5
17
6
18
std::vector<vm::i32> prog;
19
+ vm::i32 code;
20
+ while (binFile.read ((char *)&code, sizeof (code))) {
21
+ int readedBytes = binFile.gcount ();
22
+ prog.push_back (code);
23
+ }
24
+ binFile.close ();
25
+
26
+ vm::StackVM vm;
27
+
28
+ // std::vector<vm::i32> prog;
7
29
8
- prog.push_back (0b01000000000000000000000000000111 ); // push 7
9
- prog.push_back (0b01000000000000000000000000000011 ); // push 3
10
- prog.push_back (0b11000000000000000000000000000111 ); // add
11
- prog.push_back (0b01000000000000000000000000000100 ); // push 4
12
- prog.push_back (0b11000000000000000000000000000011 ); // mul
13
- prog.push_back (0b11000000000000000000000000000000 ); // halt
30
+ // prog.push_back(0b01000000000000000000000000000111); // push 7
31
+ // prog.push_back(0b01000000000000000000000000000011); // push 3
32
+ // prog.push_back(0b11000000000000000000000000000111); // add
33
+ // prog.push_back(0b01000000000000000000000000000100); // push 4
34
+ // prog.push_back(0b11000000000000000000000000000011); // mul
35
+ // prog.push_back(0b11000000000000000000000000000000); // halt
14
36
15
37
vm.loadProgram (prog);
16
38
vm.run ();
You can’t perform that action at this time.
0 commit comments