Added entry point statement

This commit is contained in:
Veit Heller
2014-10-08 12:01:57 +02:00
parent 0f81682eb8
commit efbbb37d36
3 changed files with 18 additions and 14 deletions

View File

@@ -4,6 +4,4 @@ Virtual Machines
[![Build Status](https://travis-ci.org/hellerve/Virtual-Machines.png?branch=master)](https://travis-ci.org/hellerve/Virtual-Machines) [![Build Status](https://travis-ci.org/hellerve/Virtual-Machines.png?branch=master)](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).

View File

@@ -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,6 +195,9 @@ 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.");
} }
if(strcmp(command[0], "ENTRY") == 0){
entry = (int) strtol(command[1], (char **) NULL, 10);
}else{
for(i = 1; i < len; i++) for(i = 1; i < len; i++)
if(strcmp(ins[i].name, command[0]) == 0){ if(strcmp(ins[i].name, command[0]) == 0){
code[codep++] = i; code[codep++] = i;
@@ -208,6 +212,7 @@ program vm_parse(char *filename){
} }
} }
} }
}
fclose(file); fclose(file);
@@ -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;
} }

View File

@@ -10,6 +10,7 @@
typedef struct{ typedef struct{
unsigned long length; unsigned long length;
int entrypoint;
int* code; int* code;
} program; } program;