Various fixes
This commit is contained in:
@@ -3,4 +3,5 @@ Virtual Machines
|
||||
|
||||
Just a bunch of immature interpreters. One interprets brainfuck code(nbfi -
|
||||
naive brainfuck interpreter), the other uses an assembler-like dsl(but has
|
||||
no parser until now).
|
||||
no parser until now, so you will have to write code within the original
|
||||
programs code).
|
||||
|
5
vvm/README.md
Normal file
5
vvm/README.md
Normal file
@@ -0,0 +1,5 @@
|
||||
Veits Virtual Machine
|
||||
---------------------
|
||||
|
||||
A virtual machine that executes assembler-like code.
|
||||
|
BIN
vvm/bin/vvm
BIN
vvm/bin/vvm
Binary file not shown.
@@ -5,17 +5,17 @@
|
||||
const char* opcodes[] = {"IADD", "ISUB", "IMULT", "IDIV", "IMOD",
|
||||
"ILT", "IEQ", "IGT", "BR", "BRT", "BRF", "ICONST", "LOAD", "GLOAD",
|
||||
"STORE", "GSTORE", "PRINT", "POP", "HALT", "LEQ", "GEQ", "CALL", "RET",
|
||||
"IPRINT", "FETCH"};
|
||||
"IPRINT", "FETCH", "IINC", "IDEC" };
|
||||
|
||||
int nargs[] = { 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0,
|
||||
0, 2, 0, 0, 0 };
|
||||
0, 2, 0, 0, 0, 0, 0 };
|
||||
|
||||
instruction* setup_instructions(){
|
||||
int i;
|
||||
static instruction ins[FETCH+1];
|
||||
static instruction ins[IDEC+1];
|
||||
ins[0].operands = 0;
|
||||
ins[0].name = NULL;
|
||||
for(i = 1; i <= FETCH; i++){
|
||||
for(i = 1; i <= IDEC; i++){
|
||||
ins[i].operands = nargs[i-1];
|
||||
ins[i].name = opcodes[i-1];
|
||||
}
|
||||
|
@@ -25,6 +25,8 @@
|
||||
#define RET 23
|
||||
#define IPRINT 24
|
||||
#define FETCH 25
|
||||
#define IINC 26
|
||||
#define IDEC 27
|
||||
|
||||
typedef struct{
|
||||
int operands;
|
||||
|
@@ -34,6 +34,12 @@ void vm_execute(int code[], int ip, int datasize, int length){
|
||||
disassemble(sp, fp, ip, opcode, ins, code, stack);
|
||||
}
|
||||
switch(opcode){
|
||||
case IINC:
|
||||
stack[sp]++;
|
||||
break;
|
||||
case IDEC:
|
||||
stack[sp]--;
|
||||
break;
|
||||
case LOAD:
|
||||
stack[++sp] = stack[code[ip++]+fp];
|
||||
break;
|
||||
|
Reference in New Issue
Block a user