home *** CD-ROM | disk | FTP | other *** search
/ Mac Power 1999 February / MACPOWER-1999-02.ISO.7z / MACPOWER-1999-02.ISO / 9902⁄AMUG / UTILITY / mac06-0.95.sit / mac06-0.95 / include / ucode.h < prev    next >
Text File  |  1998-08-23  |  4KB  |  157 lines

  1. /* mac06ゥ1998 by HNS/DSITRI hns@computer.org
  2. ** universal code (ucode)
  3. */
  4.  
  5. #pragma once
  6.  
  7. typedef char *uaddress;
  8.  
  9. typedef unsigned long uopcode;
  10.  
  11. typedef union udata
  12.     { /* entry in data stack */
  13.     unsigned long i;
  14.     uaddress p;
  15.     /* double d; */
  16.     } udata;
  17.  
  18. typedef union ustack
  19.     { /* entry in procedure stack */
  20.     unsigned long i;    /* data value */
  21.     uopcode *p;            /* return address */
  22.     } ustack;
  23.  
  24. struct ucode
  25.     {
  26.     uaddress text, data, bss, stack, exstack;            /* code segments */
  27.     uaddress textend, dataend, bssend, stackend, exend;    /* end of segments */
  28.     uopcode *pc;            /* program pointer */
  29.     ustack *sp;                /* call, args, auto stack pointer */
  30.     udata *dsp;                /* expression stack */
  31.     };
  32.  
  33. typedef struct longjmp
  34.     { /* longjump frame */
  35.     uopcode *pc;
  36.     ustack *sp;
  37.     udata *dsp;
  38.     long value;
  39.     };
  40.  
  41. enum { /* opcodes in upper 8 bits of command */
  42.     /* constants */
  43.     OPC_CONST=0,        /* 24 bit positive constant */
  44.     OPC_NCONST,            /* 24 bit negative constant */
  45.     OPC_HCONST,            /* 24 bit high part of constant added to tos */
  46.     OPC_FCONST,
  47.     OPC_DCONST,
  48.     OPC_TEXT=8,            /* 24 bit offset into text segment */
  49.     OPC_DATA,            /* 24 bit offset into data segment */
  50.     OPC_BSS,            /* 24 bit offset into bss segment */
  51.     /* program flow */
  52.     OPC_CALL=0x10,        /* call tos */
  53.     OPC_JMP,            /* jmp to tos */
  54.     OPC_JTRUE,            /* jump to tos if nos true */
  55.     OPC_JFALSE,            /* jump to tos if nos false */
  56.     OPC_RET,            /* return */
  57.     OPC_SETJMP,            /* set jump (tos=addr of jmpbuf) */
  58.     OPC_LONGJMP,        /* long jump (tos=addr of jmpbuf) */
  59.     /* switch/case program flow */
  60.     OPC_SWITCHSRCH,        /* search table for switch */
  61.     OPC_SWITCHJMP,        /* jmp table for switch */
  62.     /* stack manipulation */
  63.     OPC_PUSH=0x20,        /* push tos on stack */
  64.     OPC_POP,            /* pop from stack */
  65.     OPC_ALLOC,            /* allocate/deallocate space stack */
  66.     OPC_AUTO,            /* make stack offset */
  67.     /* binary arithmetic and logical operations */
  68.     OPC_ADD=0x30,
  69.     OPC_SUB,
  70.     OPC_MUL,
  71.     OPC_UMUL,
  72.     OPC_DIV,
  73.     OPC_UDIV,
  74.     OPC_MOD,
  75.     OPC_UMOD,
  76.     OPC_AND,
  77.     OPC_OR,
  78.     OPC_XOR,
  79.     /* binary shift operations */
  80.     OPC_SHL=0x40,
  81.     OPC_USHL,
  82.     OPC_SHR,
  83.     OPC_USHR,
  84.     /* binary compare operations */
  85.     OPC_LT=0x50,
  86.     OPC_ULT,
  87.     OPC_GT,
  88.     OPC_UGT,
  89.     OPC_LE,
  90.     OPC_ULE,
  91.     OPC_GE,
  92.     OPC_UGE,
  93.     OPC_EQ,
  94.     OPC_NEQ,
  95.     /* unary operations */
  96.     OPC_EQZ=0x60,
  97.     OPC_NZ,
  98.     OPC_NEG,
  99.     OPC_NOT,
  100.     OPC_CHS,
  101.     OPC_SHIFT,            /* multiply by 2 - for fast index calculations */
  102.     OPC_SEXTB,            /* sign extend byte -> long */
  103.     OPC_SEXTW,            /* sign extend word -> long */
  104.     /* working stack manipulation */
  105.     OPC_DUP=0x70,        /* duplicate value */
  106.     OPC_SWAP,            /* swap tos and nos */
  107.     OPC_DROP,            /* throw away value */
  108.     OPC_NDUP,            /* duplicate n-th value */
  109.     /* store to memory */
  110.     OPC_STOREB=0x80,
  111.     OPC_STOREW,
  112.     OPC_STOREL,
  113.     OPC_STOREF,
  114.     OPC_STORED,
  115.     /* fetch from memory */
  116.     OPC_FETCHB=0x90,
  117.     OPC_FETCHW,
  118.     OPC_FETCHL,
  119.     OPC_FETCHF,
  120.     OPC_FETCHD,
  121.     OPC_UFETCHB,
  122.     OPC_UFETCHW,
  123.     OPC_UFETCHL,
  124.     /* floating point operations */
  125.     OPC_FADD=0xa0,        /* dyadic */
  126.     OPC_FSUB,
  127.     OPC_FMUL,
  128.     OPC_FDIV,
  129.     OPC_FLT,
  130.     OPC_FULT,
  131.     OPC_FGT,
  132.     OPC_FUGT,
  133.     OPC_FLE,
  134.     OPC_FULE,
  135.     OPC_FGE,
  136.     OPC_FUGE,
  137.     OPC_FEQ,
  138.     OPC_FNEQ,
  139.     OPC_FCHS=0xb0,        /* monadic */
  140.     OPC_FEQZ,
  141.     OPC_FNZ,
  142.     OPC_LTOF,            /* long to double */
  143.     OPC_ULTOF,            /* unsigned long to double */
  144.     OPC_FTOL,            /* double to integer */
  145.     OPC_ROUND,            /* double to float truncation */
  146.     /* system call */
  147.     OPC_SVC=0xc0,        /* supervisor call */
  148.     /* builtin functions */
  149.     OPC_CPYINC,            /* block copy with inc mode */
  150.     OPC_CPYDEC,            /* block copy with dec mode */
  151.     OPC_SET,            /* set block */
  152.     OPC_SRCH            /* search in block */
  153.     };
  154.  
  155. void run(struct ucode *c, register long n);
  156.  
  157. /* EOF */