From 4e7e9e8de5b9e50694e161653ef03b5c15a53054 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Tue, 4 Apr 2000 17:48:44 -0300 Subject: new opcode INCLOCAL. --- lopcodes.h | 77 +++++++++++++++++++++++++++++++++++--------------------------- 1 file changed, 44 insertions(+), 33 deletions(-) (limited to 'lopcodes.h') diff --git a/lopcodes.h b/lopcodes.h index 71a712f2..e93f8c35 100644 --- a/lopcodes.h +++ b/lopcodes.h @@ -1,5 +1,5 @@ /* -** $Id: lopcodes.h,v 1.52 2000/03/24 19:49:23 roberto Exp roberto $ +** $Id: lopcodes.h,v 1.53 2000/03/27 14:31:12 roberto Exp roberto $ ** Opcodes for Lua virtual machine ** See Copyright Notice in lua.h */ @@ -13,26 +13,30 @@ /*=========================================================================== We assume that instructions are unsigned numbers. All instructions have an opcode in the first 6 bits. Moreover, - an instruction can have 0, 1, or 2 arguments. There are 4 types of - Instructions: + an instruction can have 0, 1, or 2 arguments. Instructions can + have the following types: type 0: no arguments type 1: 1 unsigned argument in the higher bits (called `U') type 2: 1 signed argument in the higher bits (`S') type 3: 1st unsigned argument in the higher bits (`A') 2nd unsigned argument in the middle bits (`B') - The signed argument is represented in excess 2^K; that is, the number - value is the usigned value minus 2^K. + A signed argument is represented in excess K; that is, the number + value is the unsigned value minus K. K is exactly the maximum value + for that argument (so that -max is represented by 0, and +max is + represented by 2*max), which is half the maximum for the corresponding + unsigned argument. The size of each argument is defined in `llimits.h'. The usual is an - instruction with 32 bits, U and S arguments with 26 bits (32-6), B - argument with 9 bits, and A argument with 17 bits (32-6-9). For small - instalations, the instruction size can be 16, so U and S have 10 bits, + instruction with 32 bits, U arguments with 26 bits (32-6), B arguments + with 9 bits, and A arguments with 17 bits (32-6-9). For small + instalations, the instruction size can be 16, so U has 10 bits, and A and B have 5 bits each. ===========================================================================*/ -#define EXCESS_S (1<<(SIZE_S-1)) /* == 2^K */ + +#define MAXARG_sA (MAXARG_A>>1) /* max value for a signed A */ /* creates a mask with `n' 1 bits at position `p' */ @@ -45,27 +49,33 @@ ** the following macros help to manipulate instructions */ +#define CREATE_0(o) ((Instruction)(o)) #define GET_OPCODE(i) ((OpCode)((i)&MASK1(SIZE_OP,0))) -#define GETARG_U(i) ((int)((i)>>POS_U)) -#define GETARG_S(i) ((int)((i)>>POS_S)-EXCESS_S) -#define GETARG_A(i) ((int)((i)>>POS_A)) -#define GETARG_B(i) ((int)(((i)>>POS_B) & MASK1(SIZE_B,0))) - #define SET_OPCODE(i,o) ((i) = (((i)&MASK0(SIZE_OP,0)) | (Instruction)(o))) + +#define CREATE_U(o,u) ((Instruction)(o) | (Instruction)(u)<>POS_U)) #define SETARG_U(i,u) ((i) = (((i)&MASK0(SIZE_U,POS_U)) | \ ((Instruction)(u)<>POS_A)) #define SETARG_A(i,a) ((i) = (((i)&MASK0(SIZE_A,POS_A)) | \ ((Instruction)(a)<>POS_B) & MASK1(SIZE_B,0))) #define SETARG_B(i,b) ((i) = (((i)&MASK0(SIZE_B,POS_B)) | \ ((Instruction)(b)<y)? PC+=s */ -OP_IFGEJMP,/* J y x - (x>=y)? PC+=s */ - -OP_IFTJMP,/* J x - (x!=nil)? PC+=s */ -OP_IFFJMP,/* J x - (x==nil)? PC+=s */ -OP_ONTJMP,/* J x (x!=nil)? x : - (x!=nil)? PC+=s */ -OP_ONFJMP,/* J x (x==nil)? x : - (x==nil)? PC+=s */ +OP_JMPNEQ,/* J y x - (x~=y)? PC+=s */ +OP_JMPEQ,/* J y x - (x==y)? PC+=s */ +OP_JMPLT,/* J y x - (xy)? PC+=s */ +OP_JMPGE,/* J y x - (x>=y)? PC+=s */ + +OP_JMPT,/* J x - (x!=nil)? PC+=s */ +OP_JMPF,/* J x - (x==nil)? PC+=s */ +OP_JMPONT,/* J x (x!=nil)? x : - (x!=nil)? PC+=s */ +OP_JMPONF,/* J x (x==nil)? x : - (x==nil)? PC+=s */ OP_JMP,/* J - - PC+=s */ OP_PUSHNILJMP,/* - - nil PC++; */ @@ -145,7 +156,7 @@ OP_SETLINE/* U - - LINE=u */ -#define ISJUMP(o) (OP_IFNEQJMP <= (o) && (o) <= OP_JMP) +#define ISJUMP(o) (OP_JMPNEQ <= (o) && (o) <= OP_JMP) #endif -- cgit v1.2.3-55-g6feb