2 ** $Id: opcode.c,v 1.9 1999/05/25 19:58:55 lhf Exp $
4 ** See Copyright Notice in lua.h
9 enum { /* for Opcode.args */
17 static Opcode Info
[]= /* ORDER lopcodes.h */
22 static Opcode Fake
[]= /* ORDER luac.h */
24 { "NOP", NOP
, NOP
, ARGS_NONE
, -1, -1 },
25 { "STACK", STACK
, STACK
, ARGS_B
, -1, -1 },
26 { "ARGS", ARGS
, ARGS
, ARGS_B
, -1, -1 },
27 { "VARARGS", VARARGS
, VARARGS
, ARGS_B
, -1, -1 },
30 #define NOPCODES (sizeof(Info)/sizeof(Info[0]))
32 int luaU_opcodeinfo(TProtoFunc
* tf
, Byte
* p
, Opcode
* I
, char* xFILE
, int xLINE
)
38 if (p
==code
) /* first byte is STACK */
43 else if (p
==code
+1) /* second byte is ARGS or VARARGS */
56 else if (op
==NOP
) /* NOP is fake */
60 else if (op
>=NOPCODES
) /* cannot happen */
62 luaL_verror("[%s:%d] bad opcode %d at pc=%d" IN
,
63 xFILE
,xLINE
,op
,(int)(p
-code
),INLOC
);
66 else /* ordinary opcode */
71 case ARGS_NONE
: size
=1;
73 case ARGS_B
: size
=2; OP
.arg
=p
[1];
75 case ARGS_W
: size
=3; OP
.arg
=(p
[1]<<8)+p
[2];
77 case ARGS_BB
: size
=3; OP
.arg
=p
[1]; OP
.arg2
=p
[2];
79 case ARGS_WB
: size
=4; OP
.arg
=(p
[1]<<8)+p
[2]; OP
.arg2
=p
[3];
81 default: /* cannot happen */
82 luaL_verror("[%s:%d] bad args %d for %s at pc=%d" IN
,
83 __FILE__
,__LINE__
,OP
.args
,OP
.name
,(int)(p
-code
),INLOC
);
91 int luaU_codesize(TProtoFunc
* tf
)
99 if (OP
.op
==ENDCODE
) break;