Added entry point statement
This commit is contained in:
@@ -4,6 +4,4 @@ Virtual Machines
|
|||||||
[](https://travis-ci.org/hellerve/Virtual-Machines)
|
[](https://travis-ci.org/hellerve/Virtual-Machines)
|
||||||
|
|
||||||
Just a bunch of immature interpreters. One interprets brainfuck code(nbfi -
|
Just a bunch of immature interpreters. One interprets brainfuck code(nbfi -
|
||||||
naive brainfuck interpreter), the other uses an assembly-based dsl(but has
|
naive brainfuck interpreter), the other uses an assembly-based dsl.
|
||||||
no parser until now, so you will have to write code within the original
|
|
||||||
programs' code).
|
|
||||||
|
27
vvm/src/vm.c
27
vvm/src/vm.c
@@ -178,6 +178,7 @@ program vm_parse(char *filename){
|
|||||||
instruction* ins = setup_instructions();
|
instruction* ins = setup_instructions();
|
||||||
unsigned int len = IDEC;
|
unsigned int len = IDEC;
|
||||||
size_t linelength = 0;
|
size_t linelength = 0;
|
||||||
|
int entry = 0;
|
||||||
|
|
||||||
if(!file)
|
if(!file)
|
||||||
die(127, "Could not open file.");
|
die(127, "Could not open file.");
|
||||||
@@ -194,17 +195,21 @@ program vm_parse(char *filename){
|
|||||||
die(127, "Program too big, could not allocate enough storage.");
|
die(127, "Program too big, could not allocate enough storage.");
|
||||||
}
|
}
|
||||||
|
|
||||||
for(i = 1; i < len; i++)
|
if(strcmp(command[0], "ENTRY") == 0){
|
||||||
if(strcmp(ins[i].name, command[0]) == 0){
|
entry = (int) strtol(command[1], (char **) NULL, 10);
|
||||||
code[codep++] = i;
|
}else{
|
||||||
found = TRUE;
|
for(i = 1; i < len; i++)
|
||||||
break;
|
if(strcmp(ins[i].name, command[0]) == 0){
|
||||||
}
|
code[codep++] = i;
|
||||||
|
found = TRUE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if(found && ins[i].operands > 0){
|
if(found && ins[i].operands > 0){
|
||||||
int nargs = ins[i].operands;
|
int nargs = ins[i].operands;
|
||||||
for(i = 1; i <= nargs; i++){
|
for(i = 1; i <= nargs; i++){
|
||||||
code[codep++] = (int) strtol(command[i], (char **) NULL, 10);
|
code[codep++] = (int) strtol(command[i], (char **) NULL, 10);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -216,7 +221,7 @@ program vm_parse(char *filename){
|
|||||||
|
|
||||||
code = (int *) realloc(code, codep * sizeof(int));
|
code = (int *) realloc(code, codep * sizeof(int));
|
||||||
|
|
||||||
program prog = {codep, code};
|
program prog = {codep, entry, code};
|
||||||
|
|
||||||
return prog;
|
return prog;
|
||||||
}
|
}
|
||||||
|
@@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
typedef struct{
|
typedef struct{
|
||||||
unsigned long length;
|
unsigned long length;
|
||||||
|
int entrypoint;
|
||||||
int* code;
|
int* code;
|
||||||
} program;
|
} program;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user