Updated variable name and factorial test
This commit is contained in:
@@ -11,7 +11,7 @@ int main(int argc, char** argv){
|
|||||||
program prog;
|
program prog;
|
||||||
if(argc != 2)
|
if(argc != 2)
|
||||||
die(127, "Please specify exactly one file to execute.");
|
die(127, "Please specify exactly one file to execute.");
|
||||||
prog = vm_parse(argv[1]);
|
prog = vm_compile(argv[1]);
|
||||||
vm_execute(prog.code, prog.entrypoint, 0, prog.length);
|
vm_execute(prog.code, prog.entrypoint, 0, prog.length);
|
||||||
free(prog.code);
|
free(prog.code);
|
||||||
return 0;
|
return 0;
|
||||||
|
@@ -30,8 +30,8 @@ static inline void disassemble(int sp, int fp, int ip, int opcode, instruction*
|
|||||||
void vm_execute(int code[], int ip, int datasize, unsigned long length){
|
void vm_execute(int code[], int ip, int datasize, unsigned long length){
|
||||||
int* data = (int *) alloca((size_t)datasize * sizeof(int));
|
int* data = (int *) alloca((size_t)datasize * sizeof(int));
|
||||||
int stack[MAX_SIZE];
|
int stack[MAX_SIZE];
|
||||||
int sp = -1;
|
register int sp = -1;
|
||||||
int fp = -1;
|
register int fp = -1;
|
||||||
int nargs, addr, a, b;
|
int nargs, addr, a, b;
|
||||||
instruction* ins = setup_instructions();
|
instruction* ins = setup_instructions();
|
||||||
while(ip < length){
|
while(ip < length){
|
||||||
@@ -162,7 +162,7 @@ void vm_execute(int code[], int ip, int datasize, unsigned long length){
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
program vm_parse(char *filename){
|
program vm_compile(char *filename){
|
||||||
FILE* file = fopen(filename, "r");
|
FILE* file = fopen(filename, "r");
|
||||||
char* line = NULL;
|
char* line = NULL;
|
||||||
char** command = NULL;
|
char** command = NULL;
|
||||||
|
@@ -37,7 +37,7 @@ void vm_execute(int[], int, int, unsigned long);
|
|||||||
* @brief vm_parse
|
* @brief vm_parse
|
||||||
* @param file -> filename
|
* @param file -> filename
|
||||||
*/
|
*/
|
||||||
program vm_parse(char*);
|
program vm_compile(char*);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief str_split
|
* @brief str_split
|
||||||
|
@@ -15,5 +15,7 @@ RET
|
|||||||
ICONST 12
|
ICONST 12
|
||||||
CALL 0 1
|
CALL 0 1
|
||||||
IPRINT
|
IPRINT
|
||||||
|
ICONST 10
|
||||||
|
PRINT
|
||||||
HALT
|
HALT
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user