misc/liblua/lopcodes.h
author nemo
Tue, 23 Aug 2011 16:37:57 -0400
changeset 5674 244cbc1448bd
parent 3697 d5b30d6373fc
child 10017 de822cd3df3a
permissions -rw-r--r--
Set more generous minimums. Flicker seems to have nothing to do with minimum size. I get it even for fairly large dimensions after scaling down from a much larger size. Similar to issues with zoom from about a month ago, before unc0rr fixed them.
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:
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    17
	`A' : 8 bits
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    18
	`B' : 9 bits
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    19
	`C' : 9 bits
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    20
	`Bx' : 18 bits (`B' and `C' together)
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    21
	`sBx' : signed Bx
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
*/
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    37
#define SIZE_C		9
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    38
#define SIZE_B		9
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    39
#define SIZE_Bx		(SIZE_C + SIZE_B)
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    40
#define SIZE_A		8
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    41
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    42
#define SIZE_OP		6
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    43
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    44
#define POS_OP		0
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    45
#define POS_A		(POS_OP + SIZE_OP)
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    46
#define POS_C		(POS_A + SIZE_A)
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    47
#define POS_B		(POS_C + SIZE_C)
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    48
#define POS_Bx		POS_C
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' */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    71
#define MASK1(n,p)	((~((~(Instruction)0)<<n))<<p)
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' */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    74
#define MASK0(n,p)	(~MASK1(n,p))
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
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    80
#define GET_OPCODE(i)	(cast(OpCode, ((i)>>POS_OP) & MASK1(SIZE_OP,0)))
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    81
#define SET_OPCODE(i,o)	((i) = (((i)&MASK0(SIZE_OP,POS_OP)) | \
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    82
		((cast(Instruction, o)<<POS_OP)&MASK1(SIZE_OP,POS_OP))))
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    83
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    84
#define GETARG_A(i)	(cast(int, ((i)>>POS_A) & MASK1(SIZE_A,0)))
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    85
#define SETARG_A(i,u)	((i) = (((i)&MASK0(SIZE_A,POS_A)) | \
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    86
		((cast(Instruction, u)<<POS_A)&MASK1(SIZE_A,POS_A))))
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    87
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    88
#define GETARG_B(i)	(cast(int, ((i)>>POS_B) & MASK1(SIZE_B,0)))
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    89
#define SETARG_B(i,b)	((i) = (((i)&MASK0(SIZE_B,POS_B)) | \
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    90
		((cast(Instruction, b)<<POS_B)&MASK1(SIZE_B,POS_B))))
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    91
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    92
#define GETARG_C(i)	(cast(int, ((i)>>POS_C) & MASK1(SIZE_C,0)))
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    93
#define SETARG_C(i,b)	((i) = (((i)&MASK0(SIZE_C,POS_C)) | \
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    94
		((cast(Instruction, b)<<POS_C)&MASK1(SIZE_C,POS_C))))
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    95
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    96
#define GETARG_Bx(i)	(cast(int, ((i)>>POS_Bx) & MASK1(SIZE_Bx,0)))
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    97
#define SETARG_Bx(i,b)	((i) = (((i)&MASK0(SIZE_Bx,POS_Bx)) | \
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    98
		((cast(Instruction, b)<<POS_Bx)&MASK1(SIZE_Bx,POS_Bx))))
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    99
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   100
#define GETARG_sBx(i)	(GETARG_Bx(i)-MAXARG_sBx)
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   101
#define SETARG_sBx(i,b)	SETARG_Bx((i),cast(unsigned int, (b)+MAXARG_sBx))
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   102
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   103
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   104
#define CREATE_ABC(o,a,b,c)	((cast(Instruction, o)<<POS_OP) \
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   105
			| (cast(Instruction, a)<<POS_A) \
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   106
			| (cast(Instruction, b)<<POS_B) \
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   107
			| (cast(Instruction, c)<<POS_C))
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   108
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   109
#define CREATE_ABx(o,a,bc)	((cast(Instruction, o)<<POS_OP) \
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   110
			| (cast(Instruction, a)<<POS_A) \
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   111
			| (cast(Instruction, bc)<<POS_Bx))
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) */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   119
#define BITRK		(1 << (SIZE_B - 1))
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 */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   122
#define ISK(x)		((x) & BITRK)
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 */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   125
#define INDEXK(r)	((int)(r) & ~BITRK)
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   126
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   127
#define MAXINDEXRK	(BITRK - 1)
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 */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   130
#define RKASK(x)	((x) | BITRK)
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
*/
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   136
#define NO_REG		MAXARG_A
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
/*----------------------------------------------------------------------
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   152
name		args	description
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   153
------------------------------------------------------------------------*/
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   154
OP_MOVE,/*	A B	R(A) := R(B)					*/
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   155
OP_LOADK,/*	A Bx	R(A) := Kst(Bx)					*/
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   156
OP_LOADBOOL,/*	A B C	R(A) := (Bool)B; if (C) pc++			*/
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   157
OP_LOADNIL,/*	A B	R(A) := ... := R(B) := nil			*/
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   158
OP_GETUPVAL,/*	A B	R(A) := UpValue[B]				*/
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   159
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   160
OP_GETGLOBAL,/*	A Bx	R(A) := Gbl[Kst(Bx)]				*/
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   161
OP_GETTABLE,/*	A B C	R(A) := R(B)[RK(C)]				*/
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   162
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   163
OP_SETGLOBAL,/*	A Bx	Gbl[Kst(Bx)] := R(A)				*/
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   164
OP_SETUPVAL,/*	A B	UpValue[B] := R(A)				*/
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   165
OP_SETTABLE,/*	A B C	R(A)[RK(B)] := RK(C)				*/
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   166
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   167
OP_NEWTABLE,/*	A B C	R(A) := {} (size = B,C)				*/
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   168
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   169
OP_SELF,/*	A B C	R(A+1) := R(B); R(A) := R(B)[RK(C)]		*/
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   170
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   171
OP_ADD,/*	A B C	R(A) := RK(B) + RK(C)				*/
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   172
OP_SUB,/*	A B C	R(A) := RK(B) - RK(C)				*/
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   173
OP_MUL,/*	A B C	R(A) := RK(B) * RK(C)				*/
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   174
OP_DIV,/*	A B C	R(A) := RK(B) / RK(C)				*/
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   175
OP_MOD,/*	A B C	R(A) := RK(B) % RK(C)				*/
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   176
OP_POW,/*	A B C	R(A) := RK(B) ^ RK(C)				*/
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   177
OP_UNM,/*	A B	R(A) := -R(B)					*/
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   178
OP_NOT,/*	A B	R(A) := not R(B)				*/
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   179
OP_LEN,/*	A B	R(A) := length of R(B)				*/
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   180
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   181
OP_CONCAT,/*	A B C	R(A) := R(B).. ... ..R(C)			*/
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   182
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   183
OP_JMP,/*	sBx	pc+=sBx					*/
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   184
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   185
OP_EQ,/*	A B C	if ((RK(B) == RK(C)) ~= A) then pc++		*/
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   186
OP_LT,/*	A B C	if ((RK(B) <  RK(C)) ~= A) then pc++  		*/
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   187
OP_LE,/*	A B C	if ((RK(B) <= RK(C)) ~= A) then pc++  		*/
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   188
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 2812
diff changeset
   189
OP_TEST,/*	A C	if not (R(A) <=> C) then pc++			*/
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 2812
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
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   192
OP_CALL,/*	A B C	R(A), ... ,R(A+C-2) := R(A)(R(A+1), ... ,R(A+B-1)) */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   193
OP_TAILCALL,/*	A B C	return R(A)(R(A+1), ... ,R(A+B-1))		*/
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   194
OP_RETURN,/*	A B	return R(A), ... ,R(A+B-2)	(see note)	*/
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   195
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   196
OP_FORLOOP,/*	A sBx	R(A)+=R(A+2);
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   197
			if R(A) <?= R(A+1) then { pc+=sBx; R(A+3)=R(A) }*/
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   198
OP_FORPREP,/*	A sBx	R(A)-=R(A+2); pc+=sBx				*/
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   199
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 2812
diff changeset
   200
OP_TFORLOOP,/*	A C	R(A+3), ... ,R(A+2+C) := R(A)(R(A+1), R(A+2));
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 2812
diff changeset
   201
                        if R(A+3) ~= nil then R(A+2)=R(A+3) else pc++	*/
2812
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   202
OP_SETLIST,/*	A B C	R(A)[(C-1)*FPF+i] := R(A+i), 1 <= i <= B	*/
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   203
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   204
OP_CLOSE,/*	A 	close all variables in the stack up to (>=) R(A)*/
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   205
OP_CLOSURE,/*	A Bx	R(A) := closure(KPROTO[Bx], R(A), ... ,R(A+n))	*/
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   206
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   207
OP_VARARG/*	A B	R(A), R(A+1), ..., R(A+B-1) = vararg		*/
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
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   211
#define NUM_OPCODES	(cast(int, OP_VARARG) + 1)
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
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   254
#define getOpMode(m)	(cast(enum OpMode, luaP_opmodes[m] & 3))
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   255
#define getBMode(m)	(cast(enum OpArgMask, (luaP_opmodes[m] >> 4) & 3))
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   256
#define getCMode(m)	(cast(enum OpArgMask, (luaP_opmodes[m] >> 2) & 3))
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   257
#define testAMode(m)	(luaP_opmodes[m] & (1 << 6))
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   258
#define testTMode(m)	(luaP_opmodes[m] & (1 << 7))
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 */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   265
#define LFIELDS_PER_FLUSH	50
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