sinterp.cpp
来自「《游戏编程精粹》AI程序设计源代码」· C++ 代码 · 共 40 行
CPP
40 行
#include "VM.H"
int main( int argc, char **argv )
{
// The usage to this program is very simple: it requires a single file name
// which is the bytecode stream to execute.
if ( argc != 2 ) {
printf( "usage: %s file", argv[0] );
return 1;
}
// Jump through hoops opening the file. We need to know how big to allocate
// the buffer, so make sure to seek to the end of the file to get its file
// size.
FILE *f = fopen( argv[1], "rb" );
if ( f == NULL ) {
perror( argv[1] );
return 1;
}
fseek( f, 0, SEEK_END );
size_t len = ftell( f );
rewind( f );
char *stream = new char [len];
fread( stream, len, 1, f );
// Now that we finially have the bytecode stream from the file, create an
// instance of the VM and execute it.
VM vm( stream, len );
vm.Exec();
delete [] stream;
fclose( f );
return 0;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?