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