updated readme for new version

This commit is contained in:
hellerve
2015-06-16 10:58:26 +02:00
parent 9b55ee0f54
commit 74e9c43403
7 changed files with 92 additions and 99 deletions

View File

@@ -29,41 +29,40 @@ concise as possible.
Instruction set Instruction set
--------------- ---------------
Up until now, all the operations are executed on integers(hence the Up until now, all the operations are executed on integers.
I\* prefix).
*Operations overview*: *Operations overview*:
* ENTRY - Specifies an entry point for the routine by its index. * ENTRY - Specifies an entry point for the routine by its index.
* IADD - Adds the two items to each other that are on top of the stack * ADD - Adds the two items to each other that are on top of the stack
and stores the result on top of the stack. and stores the result on top of the stack.
* ISUB - Subtracts the two items from each other that are on top of the * SUB - Subtracts the two items from each other that are on top of the
stack and stores the result on top of the stack. stack and stores the result on top of the stack.
* IMULT - Multiplies the two items to each other that are on top of the * MULT - Multiplies the two items to each other that are on top of the
stack and stores the result on top of the stack. stack and stores the result on top of the stack.
* IDIV - Performs a division operation to the two items that are on top * DIV - Performs a division operation to the two items that are on top
of the stack and stores the result on top of the stack. of the stack and stores the result on top of the stack.
* IMOD - Performs a modulo operation to the two items that are on top * MOD - Performs a modulo operation to the two items that are on top
of the stack and stores the result on top of the stack. of the stack and stores the result on top of the stack.
* ILT - Checks whether the item on top of the stack is greater than the * LT - Checks whether the item on top of the stack is greater than the
item below it and stores a boolean on top of the stack. item below it and stores a boolean on top of the stack.
* IEQ - Checks whether the item on top of the stack is equal to the * EQ - Checks whether the item on top of the stack is equal to the
item below it and stores a boolean on top of the stack. item below it and stores a boolean on top of the stack.
* IGT - Checks whether the item on top of the stack is smaller than the * GT - Checks whether the item on top of the stack is smaller than the
item below it and stores a boolean on top of the stack. item below it and stores a boolean on top of the stack.
* ILEQ - Checks whether the item on top of the stack is smaller than or * LEQ - Checks whether the item on top of the stack is smaller than or
equal to the item below it and stores a boolean on top of the stack. equal to the item below it and stores a boolean on top of the stack.
* IGEQ - Checks whether the item on top of the stack is greater than or * GEQ - Checks whether the item on top of the stack is greater than or
equal to the item below it and stores a boolean on top of the stack. equal to the item below it and stores a boolean on top of the stack.
* BR - Jumps to the instruction that is provided as an argument. * BR - Jumps to the instruction that is provided as an argument.
@@ -74,7 +73,7 @@ value on top of the stack is TRUE.
* BRF - Jumps to the instruction that is provided as an argument if the * BRF - Jumps to the instruction that is provided as an argument if the
value on top of the stack is FALSE. value on top of the stack is FALSE.
* ICONST - Puts the argument provided to the operation on top of the * CONST - Puts the argument provided to the operation on top of the
stack. stack.
* LOAD - Loads an element from any position on the stack on top of the * LOAD - Loads an element from any position on the stack on top of the
@@ -101,7 +100,7 @@ top of the stack.
* FETCH - Fetches a value. * FETCH - Fetches a value.
* IINC -Increments the value on top of the stack by one(equal to ++). * INC -Increments the value on top of the stack by one(equal to ++).
* IDEC -Decrements the value on top of the stack by one(equal to --). * DEC -Decrements the value on top of the stack by one(equal to --).

View File

@@ -6,7 +6,7 @@
* argc -> the argument counter * argc -> the argument counter
* argv -> the argument vector * argv -> the argument vector
* *
* executes code in my dsl. * executes code in my dsl/vm.
*/ */
int main(int argc, char** argv){ int main(int argc, char** argv){
program prog; program prog;

View File

@@ -1,63 +1,63 @@
#include "opcode.h" #include "opcode.h"
/*The opcodes as chars*/ /*The opcodes as chars*/
const char* opcodes[] = { "ADD", const char* opcodes[] = { "ADD",
"SUB", "SUB",
"MULT", "MULT",
"DIV", "DIV",
"MOD", "MOD",
"LT", "LT",
"EQ", "EQ",
"GT", "GT",
"BR", "BR",
"BRT", "BRT",
"BRF", "BRF",
"CONST", "CONST",
"LOAD", "LOAD",
"GLOAD", "GLOAD",
"STORE", "STORE",
"GSTORE", "GSTORE",
"PRINT", "PRINT",
"POP", "POP",
"HALT", "HALT",
"LEQ", "LEQ",
"GEQ", "GEQ",
"CALL", "CALL",
"RET", "RET",
"IPRINT", "IPRINT",
"FETCH", "FETCH",
"INC", "INC",
"DEC" "DEC"
}; };
/*The argument counter for the opcodes*/ /*The argument counter for the opcodes*/
int nargs[] = { 0, int nargs[] = { 0, /* ADD */
0, 0, /* SUB */
0, 0, /* MULT */
0, 0, /* DIV */
0, 0, /* MOD */
0, 0, /* LT */
0, 0, /* EQ */
0, 0, /* GT */
1, 1, /* BR */
1, 1, /* BRT */
1, 1, /* BRF */
1, 1, /* CONST */
1, 1, /* LOAD */
1, 1, /* GLOAD */
1, 1, /* STORE */
1, 1, /* GSTORE */
0, 0, /* PRINT */
0, 0, /* POP */
0, 0, /* HALT */
0, 0, /* LEQ */
0, 0, /* GEQ */
2, 2, /* CALL */
0, 0, /* RET */
0, 0, /* IPRINT */
0, 0, /* FETCH */
0, 0, /* INC */
0 0 /* DEC */
}; };
instruction* setup_instructions(){ instruction* setup_instructions(){

View File

@@ -69,7 +69,11 @@ typedef struct{
const char* name; const char* name;
}instruction; }instruction;
/*sets up the instruction struct*/ /**
* @brief setup_instructions
*
* sets up the instruction struct for the VM.
*/
instruction* setup_instructions(); instruction* setup_instructions();
#endif #endif

View File

@@ -6,7 +6,7 @@
/** /**
* @brief die * @brief die
* @param code -> the error code * @param code -> the error code
* @param message -> the error message * @param message -> the error message
* *
* Lets the program die and emits an error message. * Lets the program die and emits an error message.

View File

@@ -9,13 +9,13 @@
/** /**
* @brief disassemble * @brief disassemble
* @param sp -> stack pointer * @param sp -> stack pointer
* @param fp -> function pointer * @param fp -> function pointer
* @param ip -> instruction pointer * @param ip -> instruction pointer
* @param opcode -> current opcode * @param opcode -> current opcode
* @param ins -> instruction struct * @param ins -> instruction struct
* @param code -> opcodes * @param code -> opcodes
* @param stack -> stack * @param stack -> stack
* *
* prints current operations and a stack trace. * prints current operations and a stack trace.
* Is invoked if DEBUG is defined. * Is invoked if DEBUG is defined.
@@ -34,25 +34,15 @@ static inline void disassemble(int sp, int fp, int ip, int opcode, instruction*
printf("\n"); printf("\n");
} }
/**
* @brief vm_execute
* @param code -> a list of opcodes
* @param ip -> the instruction pointer
* @param datasize -> the maximal standard datasize
* @param length -> the length of the program
*
* the main virtual machine loop. takes opcodes and
* metainformation and executes it.
*/
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];
register int sp = -1; register int sp = -1;
register 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){
int opcode = code[ip]; int opcode = code[ip];
ip++; ip++;
@@ -195,7 +185,7 @@ program vm_compile(char *filename){
size_t linelength = 0; size_t linelength = 0;
int entry = 0; int entry = 0;
program prog; program prog;
if(!file) if(!file)
die(127, "Could not open file."); die(127, "Could not open file.");
@@ -229,8 +219,8 @@ program vm_compile(char *filename){
} }
if(found == FALSE){ if(found == FALSE){
fprintf(stderr, fprintf(stderr,
"Line %s called with unknown command: %s\n", "Line %s called with unknown command: %s\n",
line, command[0]); line, command[0]);
die(127, "Compilation failed."); die(127, "Compilation failed.");
} }
@@ -238,8 +228,8 @@ program vm_compile(char *filename){
if(ins[i].operands > 0){ if(ins[i].operands > 0){
int nargs = ins[i].operands; int nargs = ins[i].operands;
if(nargs != elemc-1){ if(nargs != elemc-1){
fprintf(stderr, fprintf(stderr,
"Line %s called with wrong number of arguments (got %d, expected %d)\n", "Line %s called with wrong number of arguments (got %d, expected %d)\n",
line, elemc-1, nargs); line, elemc-1, nargs);
die(127, "Compilation failed."); die(127, "Compilation failed.");
} }
@@ -249,7 +239,7 @@ program vm_compile(char *filename){
} }
} }
} }
fclose(file); fclose(file);
if(line) if(line)
@@ -260,7 +250,7 @@ program vm_compile(char *filename){
code = code_realloc; code = code_realloc;
code_realloc = NULL; code_realloc = NULL;
} }
prog.length = codep; prog.length = codep;
prog.entrypoint = entry; prog.entrypoint = entry;
prog.code = code; prog.code = code;

View File

@@ -17,10 +17,10 @@ typedef struct{
/** /**
* @brief vm_execute * @brief vm_execute
* @param code -> instructions * @param code -> instructions
* @param ip -> starting point * @param ip -> starting point
* @param datasize -> maximum data size * @param datasize -> maximum data size
* @param length -> length of program * @param length -> length of program
*/ */
void vm_execute(int[], int, int, unsigned long); void vm_execute(int[], int, int, unsigned long);
@@ -32,9 +32,9 @@ program vm_compile(char*);
/** /**
* @brief str_split * @brief str_split
* @param a_str -> the input string * @param a_str -> the input string
* @param a_delim -> the delimiter * @param a_delim -> the delimiter
* @param elemc -> the counter of elements * @param elemc -> the counter of elements
* *
*/ */
char** str_split(char*, const char, unsigned int*); char** str_split(char*, const char, unsigned int*);