misc/liblua/lopcodes.h
author alfadur
Thu, 11 Apr 2019 19:30:22 +0300
changeset 14793 6dea1ca64992
parent 10017 de822cd3df3a
permissions -rw-r--r--
implement maxteams and teamchat messages
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2812
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
     1
/*
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
     2
** $Id: lopcodes.h,v 1.125.1.1 2007/12/27 13:02:25 roberto Exp $
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
     3
** Opcodes for Lua virtual machine
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
     4
** See Copyright Notice in lua.h
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
     5
*/
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
     6
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
     7
#ifndef lopcodes_h
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
     8
#define lopcodes_h
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
     9
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    10
#include "llimits.h"
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    11
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    12
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    13
/*===========================================================================
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    14
  We assume that instructions are unsigned numbers.
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    15
  All instructions have an opcode in the first 6 bits.
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    16
  Instructions can have the following fields:
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 3697
diff changeset
    17
    `A' : 8 bits
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 3697
diff changeset
    18
    `B' : 9 bits
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 3697
diff changeset
    19
    `C' : 9 bits
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 3697
diff changeset
    20
    `Bx' : 18 bits (`B' and `C' together)
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 3697
diff changeset
    21
    `sBx' : signed Bx
2812
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    22
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    23
  A signed argument is represented in excess K; that is, the number
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    24
  value is the unsigned value minus K. K is exactly the maximum value
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    25
  for that argument (so that -max is represented by 0, and +max is
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    26
  represented by 2*max), which is half the maximum for the corresponding
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    27
  unsigned argument.
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    28
===========================================================================*/
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    29
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    30
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    31
enum OpMode {iABC, iABx, iAsBx};  /* basic instruction format */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    32
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    33
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    34
/*
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    35
** size and position of opcode arguments.
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    36
*/
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 3697
diff changeset
    37
#define SIZE_C      9
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 3697
diff changeset
    38
#define SIZE_B      9
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 3697
diff changeset
    39
#define SIZE_Bx     (SIZE_C + SIZE_B)
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 3697
diff changeset
    40
#define SIZE_A      8
2812
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    41
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 3697
diff changeset
    42
#define SIZE_OP     6
2812
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    43
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 3697
diff changeset
    44
#define POS_OP      0
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 3697
diff changeset
    45
#define POS_A       (POS_OP + SIZE_OP)
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 3697
diff changeset
    46
#define POS_C       (POS_A + SIZE_A)
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 3697
diff changeset
    47
#define POS_B       (POS_C + SIZE_C)
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 3697
diff changeset
    48
#define POS_Bx      POS_C
2812
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    49
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    50
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    51
/*
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    52
** limits for opcode arguments.
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    53
** we use (signed) int to manipulate most arguments,
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    54
** so they must fit in LUAI_BITSINT-1 bits (-1 for sign)
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    55
*/
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    56
#if SIZE_Bx < LUAI_BITSINT-1
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    57
#define MAXARG_Bx        ((1<<SIZE_Bx)-1)
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    58
#define MAXARG_sBx        (MAXARG_Bx>>1)         /* `sBx' is signed */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    59
#else
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    60
#define MAXARG_Bx        MAX_INT
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    61
#define MAXARG_sBx        MAX_INT
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    62
#endif
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    63
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    64
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    65
#define MAXARG_A        ((1<<SIZE_A)-1)
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    66
#define MAXARG_B        ((1<<SIZE_B)-1)
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    67
#define MAXARG_C        ((1<<SIZE_C)-1)
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    68
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    69
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    70
/* creates a mask with `n' 1 bits at position `p' */
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 3697
diff changeset
    71
#define MASK1(n,p)  ((~((~(Instruction)0)<<n))<<p)
2812
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    72
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    73
/* creates a mask with `n' 0 bits at position `p' */
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 3697
diff changeset
    74
#define MASK0(n,p)  (~MASK1(n,p))
2812
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    75
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    76
/*
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    77
** the following macros help to manipulate instructions
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    78
*/
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    79
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 3697
diff changeset
    80
#define GET_OPCODE(i)   (cast(OpCode, ((i)>>POS_OP) & MASK1(SIZE_OP,0)))
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 3697
diff changeset
    81
#define SET_OPCODE(i,o) ((i) = (((i)&MASK0(SIZE_OP,POS_OP)) | \
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 3697
diff changeset
    82
        ((cast(Instruction, o)<<POS_OP)&MASK1(SIZE_OP,POS_OP))))
2812
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    83
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 3697
diff changeset
    84
#define GETARG_A(i) (cast(int, ((i)>>POS_A) & MASK1(SIZE_A,0)))
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 3697
diff changeset
    85
#define SETARG_A(i,u)   ((i) = (((i)&MASK0(SIZE_A,POS_A)) | \
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 3697
diff changeset
    86
        ((cast(Instruction, u)<<POS_A)&MASK1(SIZE_A,POS_A))))
2812
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    87
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 3697
diff changeset
    88
#define GETARG_B(i) (cast(int, ((i)>>POS_B) & MASK1(SIZE_B,0)))
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 3697
diff changeset
    89
#define SETARG_B(i,b)   ((i) = (((i)&MASK0(SIZE_B,POS_B)) | \
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 3697
diff changeset
    90
        ((cast(Instruction, b)<<POS_B)&MASK1(SIZE_B,POS_B))))
2812
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    91
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 3697
diff changeset
    92
#define GETARG_C(i) (cast(int, ((i)>>POS_C) & MASK1(SIZE_C,0)))
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 3697
diff changeset
    93
#define SETARG_C(i,b)   ((i) = (((i)&MASK0(SIZE_C,POS_C)) | \
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 3697
diff changeset
    94
        ((cast(Instruction, b)<<POS_C)&MASK1(SIZE_C,POS_C))))
2812
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    95
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 3697
diff changeset
    96
#define GETARG_Bx(i)    (cast(int, ((i)>>POS_Bx) & MASK1(SIZE_Bx,0)))
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 3697
diff changeset
    97
#define SETARG_Bx(i,b)  ((i) = (((i)&MASK0(SIZE_Bx,POS_Bx)) | \
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 3697
diff changeset
    98
        ((cast(Instruction, b)<<POS_Bx)&MASK1(SIZE_Bx,POS_Bx))))
2812
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    99
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 3697
diff changeset
   100
#define GETARG_sBx(i)   (GETARG_Bx(i)-MAXARG_sBx)
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 3697
diff changeset
   101
#define SETARG_sBx(i,b) SETARG_Bx((i),cast(unsigned int, (b)+MAXARG_sBx))
2812
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   102
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   103
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 3697
diff changeset
   104
#define CREATE_ABC(o,a,b,c) ((cast(Instruction, o)<<POS_OP) \
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 3697
diff changeset
   105
            | (cast(Instruction, a)<<POS_A) \
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 3697
diff changeset
   106
            | (cast(Instruction, b)<<POS_B) \
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 3697
diff changeset
   107
            | (cast(Instruction, c)<<POS_C))
2812
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   108
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 3697
diff changeset
   109
#define CREATE_ABx(o,a,bc)  ((cast(Instruction, o)<<POS_OP) \
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 3697
diff changeset
   110
            | (cast(Instruction, a)<<POS_A) \
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 3697
diff changeset
   111
            | (cast(Instruction, bc)<<POS_Bx))
2812
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   112
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   113
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   114
/*
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   115
** Macros to operate RK indices
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   116
*/
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   117
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   118
/* this bit 1 means constant (0 means register) */
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 3697
diff changeset
   119
#define BITRK       (1 << (SIZE_B - 1))
2812
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   120
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   121
/* test whether value is a constant */
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 3697
diff changeset
   122
#define ISK(x)      ((x) & BITRK)
2812
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   123
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   124
/* gets the index of the constant */
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 3697
diff changeset
   125
#define INDEXK(r)   ((int)(r) & ~BITRK)
2812
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   126
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 3697
diff changeset
   127
#define MAXINDEXRK  (BITRK - 1)
2812
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   128
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   129
/* code a constant index as a RK value */
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 3697
diff changeset
   130
#define RKASK(x)    ((x) | BITRK)
2812
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   131
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   132
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   133
/*
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   134
** invalid register that fits in 8 bits
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   135
*/
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 3697
diff changeset
   136
#define NO_REG      MAXARG_A
2812
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   137
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   138
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   139
/*
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   140
** R(x) - register
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   141
** Kst(x) - constant (in constant table)
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   142
** RK(x) == if ISK(x) then Kst(INDEXK(x)) else R(x)
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   143
*/
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   144
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   145
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   146
/*
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   147
** grep "ORDER OP" if you change these enums
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   148
*/
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   149
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   150
typedef enum {
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   151
/*----------------------------------------------------------------------
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 3697
diff changeset
   152
name        args    description
2812
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   153
------------------------------------------------------------------------*/
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 3697
diff changeset
   154
OP_MOVE,/*  A B R(A) := R(B)                    */
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 3697
diff changeset
   155
OP_LOADK,/* A Bx    R(A) := Kst(Bx)                 */
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 3697
diff changeset
   156
OP_LOADBOOL,/*  A B C   R(A) := (Bool)B; if (C) pc++            */
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 3697
diff changeset
   157
OP_LOADNIL,/*   A B R(A) := ... := R(B) := nil          */
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 3697
diff changeset
   158
OP_GETUPVAL,/*  A B R(A) := UpValue[B]              */
2812
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   159
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 3697
diff changeset
   160
OP_GETGLOBAL,/* A Bx    R(A) := Gbl[Kst(Bx)]                */
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 3697
diff changeset
   161
OP_GETTABLE,/*  A B C   R(A) := R(B)[RK(C)]             */
2812
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   162
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 3697
diff changeset
   163
OP_SETGLOBAL,/* A Bx    Gbl[Kst(Bx)] := R(A)                */
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 3697
diff changeset
   164
OP_SETUPVAL,/*  A B UpValue[B] := R(A)              */
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 3697
diff changeset
   165
OP_SETTABLE,/*  A B C   R(A)[RK(B)] := RK(C)                */
2812
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   166
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 3697
diff changeset
   167
OP_NEWTABLE,/*  A B C   R(A) := {} (size = B,C)             */
2812
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   168
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 3697
diff changeset
   169
OP_SELF,/*  A B C   R(A+1) := R(B); R(A) := R(B)[RK(C)]     */
2812
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   170
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 3697
diff changeset
   171
OP_ADD,/*   A B C   R(A) := RK(B) + RK(C)               */
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 3697
diff changeset
   172
OP_SUB,/*   A B C   R(A) := RK(B) - RK(C)               */
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 3697
diff changeset
   173
OP_MUL,/*   A B C   R(A) := RK(B) * RK(C)               */
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 3697
diff changeset
   174
OP_DIV,/*   A B C   R(A) := RK(B) / RK(C)               */
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 3697
diff changeset
   175
OP_MOD,/*   A B C   R(A) := RK(B) % RK(C)               */
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 3697
diff changeset
   176
OP_POW,/*   A B C   R(A) := RK(B) ^ RK(C)               */
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 3697
diff changeset
   177
OP_UNM,/*   A B R(A) := -R(B)                   */
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 3697
diff changeset
   178
OP_NOT,/*   A B R(A) := not R(B)                */
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 3697
diff changeset
   179
OP_LEN,/*   A B R(A) := length of R(B)              */
2812
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   180
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 3697
diff changeset
   181
OP_CONCAT,/*    A B C   R(A) := R(B).. ... ..R(C)           */
2812
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   182
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 3697
diff changeset
   183
OP_JMP,/*   sBx pc+=sBx                 */
2812
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   184
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 3697
diff changeset
   185
OP_EQ,/*    A B C   if ((RK(B) == RK(C)) ~= A) then pc++        */
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 3697
diff changeset
   186
OP_LT,/*    A B C   if ((RK(B) <  RK(C)) ~= A) then pc++        */
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 3697
diff changeset
   187
OP_LE,/*    A B C   if ((RK(B) <= RK(C)) ~= A) then pc++        */
2812
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   188
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 3697
diff changeset
   189
OP_TEST,/*  A C if not (R(A) <=> C) then pc++           */
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 3697
diff changeset
   190
OP_TESTSET,/*   A B C   if (R(B) <=> C) then R(A) := R(B) else pc++ */
2812
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   191
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 3697
diff changeset
   192
OP_CALL,/*  A B C   R(A), ... ,R(A+C-2) := R(A)(R(A+1), ... ,R(A+B-1)) */
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 3697
diff changeset
   193
OP_TAILCALL,/*  A B C   return R(A)(R(A+1), ... ,R(A+B-1))      */
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 3697
diff changeset
   194
OP_RETURN,/*    A B return R(A), ... ,R(A+B-2)  (see note)  */
2812
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   195
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 3697
diff changeset
   196
OP_FORLOOP,/*   A sBx   R(A)+=R(A+2);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 3697
diff changeset
   197
            if R(A) <?= R(A+1) then { pc+=sBx; R(A+3)=R(A) }*/
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 3697
diff changeset
   198
OP_FORPREP,/*   A sBx   R(A)-=R(A+2); pc+=sBx               */
2812
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   199
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 3697
diff changeset
   200
OP_TFORLOOP,/*  A C R(A+3), ... ,R(A+2+C) := R(A)(R(A+1), R(A+2));
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 3697
diff changeset
   201
                        if R(A+3) ~= nil then R(A+2)=R(A+3) else pc++   */
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 3697
diff changeset
   202
OP_SETLIST,/*   A B C   R(A)[(C-1)*FPF+i] := R(A+i), 1 <= i <= B    */
2812
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   203
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 3697
diff changeset
   204
OP_CLOSE,/* A   close all variables in the stack up to (>=) R(A)*/
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 3697
diff changeset
   205
OP_CLOSURE,/*   A Bx    R(A) := closure(KPROTO[Bx], R(A), ... ,R(A+n))  */
2812
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   206
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 3697
diff changeset
   207
OP_VARARG/* A B R(A), R(A+1), ..., R(A+B-1) = vararg        */
2812
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   208
} OpCode;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   209
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   210
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 3697
diff changeset
   211
#define NUM_OPCODES (cast(int, OP_VARARG) + 1)
2812
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   212
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   213
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   214
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   215
/*===========================================================================
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   216
  Notes:
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   217
  (*) In OP_CALL, if (B == 0) then B = top. C is the number of returns - 1,
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   218
      and can be 0: OP_CALL then sets `top' to last_result+1, so
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   219
      next open instruction (OP_CALL, OP_RETURN, OP_SETLIST) may use `top'.
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   220
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   221
  (*) In OP_VARARG, if (B == 0) then use actual number of varargs and
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   222
      set top (like in OP_CALL with C == 0).
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   223
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   224
  (*) In OP_RETURN, if (B == 0) then return up to `top'
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   225
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   226
  (*) In OP_SETLIST, if (B == 0) then B = `top';
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   227
      if (C == 0) then next `instruction' is real C
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   228
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   229
  (*) For comparisons, A specifies what condition the test should accept
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   230
      (true or false).
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   231
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   232
  (*) All `skips' (pc++) assume that next instruction is a jump
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   233
===========================================================================*/
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   234
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   235
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   236
/*
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   237
** masks for instruction properties. The format is:
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   238
** bits 0-1: op mode
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   239
** bits 2-3: C arg mode
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   240
** bits 4-5: B arg mode
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   241
** bit 6: instruction set register A
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   242
** bit 7: operator is a test
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 2812
diff changeset
   243
*/
2812
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   244
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   245
enum OpArgMask {
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   246
  OpArgN,  /* argument is not used */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   247
  OpArgU,  /* argument is used */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   248
  OpArgR,  /* argument is a register or a jump offset */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   249
  OpArgK   /* argument is a constant or register/constant */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   250
};
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   251
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   252
LUAI_DATA const lu_byte luaP_opmodes[NUM_OPCODES];
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   253
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 3697
diff changeset
   254
#define getOpMode(m)    (cast(enum OpMode, luaP_opmodes[m] & 3))
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 3697
diff changeset
   255
#define getBMode(m) (cast(enum OpArgMask, (luaP_opmodes[m] >> 4) & 3))
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 3697
diff changeset
   256
#define getCMode(m) (cast(enum OpArgMask, (luaP_opmodes[m] >> 2) & 3))
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 3697
diff changeset
   257
#define testAMode(m)    (luaP_opmodes[m] & (1 << 6))
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 3697
diff changeset
   258
#define testTMode(m)    (luaP_opmodes[m] & (1 << 7))
2812
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   259
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   260
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   261
LUAI_DATA const char *const luaP_opnames[NUM_OPCODES+1];  /* opcode names */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   262
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   263
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   264
/* number of list items to accumulate before a SETLIST instruction */
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 3697
diff changeset
   265
#define LFIELDS_PER_FLUSH   50
2812
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   266
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   267
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   268
#endif