Skip to content

Commit

Permalink
implement a vm interface for the compiler (opcodes 31 and 32) - at cu…
Browse files Browse the repository at this point in the history
…rrent untested.
  • Loading branch information
root committed Aug 8, 2009
1 parent f0f968f commit 2e653c1
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 79 deletions.
4 changes: 3 additions & 1 deletion README
Expand Up @@ -19,7 +19,9 @@ It is uncommon mainly in tree aspects (when finished):

Current status:

* The vm is usable but the compiler part isn't finished yet.
* The vm is usable and the compiler is finished but it's
integration into the vm is at current untested so some tests
are needed to figure out possible bugs in the vm interface.

Compilation:

Expand Down
2 changes: 1 addition & 1 deletion source/retro.c
@@ -1,3 +1,3 @@
//FLAGS -O -fomit-frame-pointer -fno-crossjumping
//LIBS ncurses
//USES devices disassemble endian initial_image loader ngaro vm
//USES devices_ioctl disassemble endian initial_image loader ngaro vm
22 changes: 21 additions & 1 deletion source/vm.c
Expand Up @@ -501,7 +501,27 @@ void vm_process(VM *vm)
vm->ports[0] = 1;
}
vm->ip++;
NEXT;
NEXT;

/***************************************************/
/* STREAM Compile stream to trace. */
/* Opcode: 31 Stack: - a Address: - */
/***************************************************/

fVM_STREAM: vm->sp++;
TOS = acc;
acc = comp_cofs;
CNEXT;

/***************************************************/
/* AOT execute trace */
/* Opcode: 32 Stack: a - i Address: - */
/***************************************************/

fVM_AOT: a = vm->data[vm->sp-1];
b = vm->data[vm->sp-2];
acc = execute (acc, a, b)
NEXT;

/* compiler routines */

Expand Down
154 changes: 78 additions & 76 deletions source/vm.h
Expand Up @@ -37,7 +37,7 @@ enum vm_opcode {VM_NOP, VM_LIT, VM_DUP, VM_DROP, VM_SWAP, VM_PUSH, VM_POP,
VM_NE_JUMP,VM_EQ_JUMP, VM_FETCH, VM_STORE, VM_ADD,
VM_SUB, VM_MUL, VM_DIVMOD, VM_AND, VM_OR, VM_XOR, VM_SHL,
VM_SHR, VM_ZERO_EXIT, VM_INC, VM_DEC, VM_IN, VM_OUT,
VM_WAIT,
VM_WAIT, VM_STREAM, VM_AOT,

/* extended-instruction set */

Expand All @@ -60,7 +60,7 @@ enum vm_opcode {VM_NOP, VM_LIT, VM_DUP, VM_DROP, VM_SWAP, VM_PUSH, VM_POP,
{ \
case VM_NOP: goto fVM_NOP; \
case VM_LIT: goto fVM_LIT; \
case VM_DUP: goto fVM_DUP; \
case VM_DUP: goto fVM_DUP; \
case VM_DROP: goto fVM_DROP; \
case VM_SWAP: goto fVM_SWAP; \
case VM_PUSH: goto fVM_PUSH; \
Expand All @@ -69,7 +69,7 @@ enum vm_opcode {VM_NOP, VM_LIT, VM_DUP, VM_DROP, VM_SWAP, VM_PUSH, VM_POP,
case VM_JUMP: goto fVM_JUMP; \
case VM_RETURN: goto fVM_RETURN; \
case VM_GT_JUMP: goto fVM_GT_JUMP; \
case VM_LT_JUMP: goto fVM_LT_JUMP; \
case VM_LT_JUMP: goto fVM_LT_JUMP; \
case VM_NE_JUMP: goto fVM_NE_JUMP; \
case VM_EQ_JUMP: goto fVM_EQ_JUMP; \
case VM_FETCH: goto fVM_FETCH; \
Expand All @@ -88,7 +88,9 @@ enum vm_opcode {VM_NOP, VM_LIT, VM_DUP, VM_DROP, VM_SWAP, VM_PUSH, VM_POP,
case VM_DEC: goto fVM_DEC; \
case VM_IN: goto fVM_IN; \
case VM_OUT: goto fVM_OUT; \
case VM_WAIT: goto fVM_WAIT; \
case VM_WAIT: goto fVM_WAIT; \
case VM_STREAM: goto fVM_STREAM; \
case VM_AOT: goto fVM_AOT; \
default: goto fVM_DEFAULT; \
}

Expand All @@ -98,7 +100,7 @@ enum vm_opcode {VM_NOP, VM_LIT, VM_DUP, VM_DROP, VM_SWAP, VM_PUSH, VM_POP,
{ \
case VM_NOP: goto cVM_NOP; \
case VM_LIT: goto cVM_LIT; \
case VM_DUP: goto cVM_DUP; \
case VM_DUP: goto cVM_DUP; \
case VM_DROP: goto cVM_DROP; \
case VM_SWAP: goto cVM_SWAP; \
case VM_PUSH: goto cVM_PUSH; \
Expand All @@ -107,7 +109,7 @@ enum vm_opcode {VM_NOP, VM_LIT, VM_DUP, VM_DROP, VM_SWAP, VM_PUSH, VM_POP,
case VM_JUMP: goto cVM_JUMP; \
case VM_RETURN: goto cVM_RETURN; \
case VM_GT_JUMP: goto cVM_GT_JUMP; \
case VM_LT_JUMP: goto cVM_LT_JUMP; \
case VM_LT_JUMP: goto cVM_LT_JUMP; \
case VM_NE_JUMP: goto cVM_NE_JUMP; \
case VM_EQ_JUMP: goto cVM_EQ_JUMP; \
case VM_FETCH: goto cVM_FETCH; \
Expand All @@ -127,76 +129,76 @@ enum vm_opcode {VM_NOP, VM_LIT, VM_DUP, VM_DROP, VM_SWAP, VM_PUSH, VM_POP,
case VM_IN: goto cVM_IN; \
case VM_OUT: goto cVM_OUT; \
case VM_WAIT: goto cVM_WAIT; \
case VM_LIA: goto cVM_LIA; \
case VM_PSAD: goto cVM_PSAD; \
case VM_PSAR: goto cVM_PSAR; \
case VM_PLDA: goto cVM_PLDA; \
case VM_PLRA: goto cVM_PLRA; \
case VM_TDA: goto cVM_TDA; \
case VM_TRA: goto cVM_TRA; \
case VM_TAD: goto cVM_TAD; \
case VM_TAR: goto cVM_TAR; \
case VM_TAB: goto cVM_TAB; \
case VM_TBA: goto cVM_TBA; \
case VM_ADDA: goto cVM_ADDA; \
case VM_SUBA: goto cVM_SUBA; \
case VM_DIVA: goto cVM_DIVA; \
case VM_MULA: goto cVM_MULA; \
case VM_INCA: goto cVM_INCA; \
case VM_DECA: goto cVM_DECA; \
case VM_ANDA: goto cVM_ANDA; \
case VM_GORA: goto cVM_GORA; \
case VM_XORA: goto cVM_XORA; \
case VM_SHLA: goto cVM_SHLA; \
case VM_SLIA: goto cVM_SLIA; \
case VM_SHRA: goto cVM_SHRA; \
case VM_SRIA: goto cVM_SRIA; \
case VM_CMPA: goto cVM_CMPA; \
case VM_LDRA: goto cVM_LDRA; \
case VM_STRA: goto cVM_STRA; \
case VM_LIB: goto cVM_LIB; \
case VM_PSBD: goto cVM_PSBD; \
case VM_PSBR: goto cVM_PSBR; \
case VM_PLDB: goto cVM_PLDB; \
case VM_PLRB: goto cVM_PLRB; \
case VM_TDB: goto cVM_TDB; \
case VM_TRB: goto cVM_TRB; \
case VM_ADDB: goto cVM_ADDB; \
case VM_SUBB: goto cVM_SUBB; \
case VM_DIVB: goto cVM_DIVB; \
case VM_MULB: goto cVM_MULB; \
case VM_INCB: goto cVM_INCB; \
case VM_DECB: goto cVM_DECB; \
case VM_ANDB: goto cVM_ANDB; \
case VM_GORB: goto cVM_GORB; \
case VM_XORB: goto cVM_XORB; \
case VM_CMPB: goto cVM_CMPB; \
case VM_SHLB: goto cVM_SHLB; \
case VM_SLIB: goto cVM_SLIB; \
case VM_SHRB: goto cVM_SHRB; \
case VM_SRIB: goto cVM_SRIB; \
case VM_LDRB: goto cVM_LDRB; \
case VM_STRB: goto cVM_STRB; \
case VM_CI: goto cVM_CI; \
case VM_CIEQ: goto cVM_CIEQ; \
case VM_CIGR: goto cVM_CIGR; \
case VM_CILE: goto cVM_CILE; \
case VM_CNZA: goto cVM_CNZA; \
case VM_CIZA: goto cVM_CIZA; \
case VM_CNZB: goto cVM_CNZB; \
case VM_CIZB: goto cVM_CIZB; \
case VM_CRA: goto cVM_CRA; \
case VM_CRB: goto cVM_CRB; \
case VM_BRA: goto cVM_BRA; \
case VM_BRB: goto cVM_BRB; \
case VM_BI: goto cVM_BI; \
case VM_BIEQ: goto cVM_BIEQ; \
case VM_BIGR: goto cVM_BIGR; \
case VM_BILE: goto cVM_BILE; \
case VM_BNZA: goto cVM_BNZA; \
case VM_BIZA: goto cVM_BIZA; \
case VM_BNZB: goto cVM_BNZB; \
case VM_BIZB: goto cVM_BIZB; \
case VM_LIA: goto cVM_LIA; \
case VM_PSAD: goto cVM_PSAD; \
case VM_PSAR: goto cVM_PSAR; \
case VM_PLDA: goto cVM_PLDA; \
case VM_PLRA: goto cVM_PLRA; \
case VM_TDA: goto cVM_TDA; \
case VM_TRA: goto cVM_TRA; \
case VM_TAD: goto cVM_TAD; \
case VM_TAR: goto cVM_TAR; \
case VM_TAB: goto cVM_TAB; \
case VM_TBA: goto cVM_TBA; \
case VM_ADDA: goto cVM_ADDA; \
case VM_SUBA: goto cVM_SUBA; \
case VM_DIVA: goto cVM_DIVA; \
case VM_MULA: goto cVM_MULA; \
case VM_INCA: goto cVM_INCA; \
case VM_DECA: goto cVM_DECA; \
case VM_ANDA: goto cVM_ANDA; \
case VM_GORA: goto cVM_GORA; \
case VM_XORA: goto cVM_XORA; \
case VM_SHLA: goto cVM_SHLA; \
case VM_SLIA: goto cVM_SLIA; \
case VM_SHRA: goto cVM_SHRA; \
case VM_SRIA: goto cVM_SRIA; \
case VM_CMPA: goto cVM_CMPA; \
case VM_LDRA: goto cVM_LDRA; \
case VM_STRA: goto cVM_STRA; \
case VM_LIB: goto cVM_LIB; \
case VM_PSBD: goto cVM_PSBD; \
case VM_PSBR: goto cVM_PSBR; \
case VM_PLDB: goto cVM_PLDB; \
case VM_PLRB: goto cVM_PLRB; \
case VM_TDB: goto cVM_TDB; \
case VM_TRB: goto cVM_TRB; \
case VM_ADDB: goto cVM_ADDB; \
case VM_SUBB: goto cVM_SUBB; \
case VM_DIVB: goto cVM_DIVB; \
case VM_MULB: goto cVM_MULB; \
case VM_INCB: goto cVM_INCB; \
case VM_DECB: goto cVM_DECB; \
case VM_ANDB: goto cVM_ANDB; \
case VM_GORB: goto cVM_GORB; \
case VM_XORB: goto cVM_XORB; \
case VM_CMPB: goto cVM_CMPB; \
case VM_SHLB: goto cVM_SHLB; \
case VM_SLIB: goto cVM_SLIB; \
case VM_SHRB: goto cVM_SHRB; \
case VM_SRIB: goto cVM_SRIB; \
case VM_LDRB: goto cVM_LDRB; \
case VM_STRB: goto cVM_STRB; \
case VM_CI: goto cVM_CI; \
case VM_CIEQ: goto cVM_CIEQ; \
case VM_CIGR: goto cVM_CIGR; \
case VM_CILE: goto cVM_CILE; \
case VM_CNZA: goto cVM_CNZA; \
case VM_CIZA: goto cVM_CIZA; \
case VM_CNZB: goto cVM_CNZB; \
case VM_CIZB: goto cVM_CIZB; \
case VM_CRA: goto cVM_CRA; \
case VM_CRB: goto cVM_CRB; \
case VM_BRA: goto cVM_BRA; \
case VM_BRB: goto cVM_BRB; \
case VM_BI: goto cVM_BI; \
case VM_BIEQ: goto cVM_BIEQ; \
case VM_BIGR: goto cVM_BIGR; \
case VM_BILE: goto cVM_BILE; \
case VM_BNZA: goto cVM_BNZA; \
case VM_BIZA: goto cVM_BIZA; \
case VM_BNZB: goto cVM_BNZB; \
case VM_BIZB: goto cVM_BIZB; \
default: goto cVM_DEFAULT; \
}
#define CNEXT vm->ip++; INEXT
Expand Down

0 comments on commit 2e653c1

Please sign in to comment.