1 /*
2  * Copyright (C) 2000-2005 Chris Ross and various contributors
3  * Copyright (C) 1999-2000 Chris Ross
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are met:
8  *
9  * o Redistributions of source code must retain the above copyright notice, this
10  *   list of conditions and the following disclaimer.
11  * o Redistributions in binary form must reproduce the above copyright notice,
12  *   this list of conditions and the following disclaimer in the documentation
13  *   and/or other materials provided with the distribution.
14  * o Neither the name of the ferite software nor the names of its contributors may
15  *   be used to endorse or promote products derived from this software without
16  *   specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28  * POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 #ifndef __FERITE_OPCODE_H__
32 # define __FERITE_OPCODE_H__
33 
34 /* the instructions we have
35  * Note: all instructions opdata_* is a FeriteVariable *except* CALL_FUNC */
36 
37 # define F_OP_NOP           0     /* no op */
38 # define F_OP_BINARY        1     /* call binary opcode->op with opcode->opdata_one & two as data items */
39 # define F_OP_UNARY         2     /* call unary operator opcode->op with op->opdata_one */
40 # define F_OP_FUNCTION      3     /* call a function (char *)opcode->opdata_one as the
41                                    * object, (char *)opcode->opdata_two as the function
42                                    * job of called function to pull items off stack
43                                    * and then push its result onto the stack */
44 # define F_OP_METHOD        4
45 # define F_OP_NEWOBJ        5
46 # define F_OP_JMP           6     /* just jump */
47 # define F_OP_EXIT          7     /* used as a return type thing =P ie to signal end of execution */
48 # define F_OP_PUSH          8
49 # define F_OP_PUSHVAR       9     /* push variable onto stack */
50 # define F_OP_PUSHINDEX     10    /* push a function variable onto the stack */
51 # define F_OP_PUSHATTR      11    /* push an object attribute onto the stack */
52 # define F_OP_POP           12    /* pop variable from stack -> ie to get rid of shit pushed onto the stack */
53 # define F_OP_BIE           13
54 # define F_OP_BNE           14    /* jump if the staus flag marks the old false, else ignore and continue */
55 # define F_OP_CLSRE_ASSGN   15
56 # define F_OP_ERR           16
57 # define F_OP_MANY          17
58 # define F_OP_CASE          18
59 # define F_OP_ARGS          19
60 # define F_OP_DELIVER         20
61 # define F_OP_SET_DELIVER     21
62 # define F_OP_GET_DELIVER     22
63 # define F_OP_SWAP_TOP        23
64 # define F_OP_VRST            24
65 
66 # define OP_MANY( p, o, d) \
67    p->OP_TYPE = F_OP_MANY; \
68    p->addr = o; \
69    p->opdata = d;
70 
71 # define OP_BINARY( ptr, opf, data1 ) \
72    ptr->OP_TYPE = F_OP_BINARY;       \
73    ptr->addr = opf;                  \
74    ptr->opdata = data1;
75 
76 # define OP_UNARY( ptr, opf, data1 )  \
77    ptr->OP_TYPE = F_OP_UNARY;        \
78    ptr->addr = opf;                  \
79    ptr->opdata = data1;
80 
81 # define OP_PUSH( ptr, data1 )        \
82    ptr->OP_TYPE = F_OP_PUSH;         \
83    ptr->opdata = data1;
84 
85 # define OP_INDEX( ptr, data1 )   \
86    ptr->OP_TYPE = F_OP_PUSHINDEX;    \
87    ptr->addr = data1;
88 
89 void ferite_delete_opcode_list( FeriteScript *script, FeriteOpcodeList *oplist );
90 FeriteOpcodeList *ferite_create_opcode_list( int size );
91 void ferite_oplist_grow( FeriteOpcodeList *oplist );
92 FeriteOp *ferite_get_next_op( FeriteOpcodeList *list );
93 FeriteOp *ferite_create_op(void);
94 FeriteOp *ferite_current_op( FeriteOpcodeList *oplist );
95 FeriteOp *ferite_get_next_op_address( FeriteOpcodeList *oplist );
96 int       ferite_get_next_op_loc( FeriteOpcodeList *oplist ); /* same as ferite_get_next_op_address
97                                                                * but will return an index rather than
98                                                                * address :)
99                                                                */
100 void ferite_opcode_dump( FeriteOpcodeList *oplist );
101 FeriteOpcodeList *ferite_opcode_dup( FeriteScript *script, FeriteOpcodeList *oplist );
102 
103 #endif /* __FERITE_OPCODE_H__ */
104