vsm

virtual stack machine for plan9
git clone git://nsmpr.xyz/vsm.git
Log | Files | Refs

vsm.h (1599B)


      1 #define CELL s32int
      2 #define IMAGE_SIZE 64 * 1024
      3 #define STACK_DEPTH 512
      4 typedef void (*instruction)(void);
      5 
      6 /* Memory */
      7 
      8 typedef struct Mapentry Mapentry;
      9 
     10 struct Mapentry {
     11 	int id;
     12 	void *vp;
     13 };
     14 
     15 Mapentry *map;
     16 usize mapsize;
     17 
     18 int _mapget(int, Mapentry **);
     19 void * mapget(int);
     20 void   mapset(int, void *);
     21 
     22 /* Operators */
     23 
     24 enum {
     25 	VSM_NOP,
     26 /* ALU: */
     27 	VSM_ADD, VSM_SUB, VSM_AND, VSM_OR, VSM_XOR,
     28 /* Stack Manipulation: */
     29 	VSM_DROP, VSM_DUP, VSM_OVER, VSM_SWAP, VSM_TOR, VSM_FROMR,
     30 /* Memory Management: */
     31 	VSM_STORE, VSM_FETCH,
     32 /* Literals: */
     33 	VSM_LIT,
     34 /* Conditional Branching: */
     35 	VSM_IF,
     36 /* Subroutine Calls: */
     37 	VSM_CALL, VSM_EXIT,
     38 /* "Hardware" IO: */
     39 	VSM_PUTC, VSM_GETC,
     40 /* this should be at the end of enum def: */
     41 	NUM_OPS,
     42 };
     43 
     44 
     45 CELL pc;
     46 CELL ir;
     47 
     48 /* Stack */
     49 
     50 CELL dstack[STACK_DEPTH], *dsp;
     51 CELL rstack[STACK_DEPTH], *rsp;
     52 
     53 /* Program Memory */
     54 
     55 CELL mar;
     56 CELL ram[IMAGE_SIZE];
     57 
     58 /* Input/Output */
     59 
     60 
     61 /* Instructions */
     62 
     63 void i_NOP(void);
     64 
     65 /* ALU: */
     66 void i_ADD(void);
     67 void i_SUB(void);
     68 void i_AND(void);
     69 void i_OR(void);
     70 void i_XOR(void);
     71 
     72 /* Stack Manipulation: */
     73 void i_DROP(void);
     74 void i_DUP(void);
     75 void i_OVER(void);
     76 void i_SWAP(void);
     77 void i_TOR(void);
     78 void i_FROMR(void);
     79 
     80 /* Memory Management: */
     81 void i_STORE(void);
     82 void i_FETCH(void);
     83 
     84 /* Literals: */
     85 void i_LIT(void);
     86 
     87 /* Conditional Branching: */
     88 void i_IF(void);
     89 
     90 /* Subroutine Calls: */
     91 void i_CALL(void);
     92 void i_EXIT(void);
     93 
     94 /* "Hardware" IO */
     95 void i_PUTC(void);
     96 void i_GETC(void);
     97 
     98 /* VMS Control */
     99 
    100 void vsm_exec(CELL);
    101 void vsm_halt(void);
    102 int  vsm_readimage(char*);
    103 void vsm_reset(void);
    104 void vsm_run(void);