Fixed behavior of VTerm when driver is set at runtime
[tpg/acess2.git] / Usermode / Libraries / libspiderscript.so_src / ast.h
1 /*
2  */
3 #ifndef _AST_H_
4 #define _AST_H_
5
6 #include <spiderscript.h>
7
8 typedef struct sAST_Script      tAST_Script;
9 typedef struct sAST_Function    tAST_Function;
10 typedef struct sAST_Node        tAST_Node;
11 typedef enum eAST_NodeTypes     tAST_NodeType;
12
13 /**
14  * \brief Node Types
15  */
16 enum eAST_NodeTypes
17 {
18         NODETYPE_NOP,
19         
20         NODETYPE_BLOCK, //!< Node Block
21         
22         NODETYPE_VARIABLE,      //!< Variable
23         NODETYPE_CONSTANT,      //!< Runtime Constant
24         NODETYPE_STRING,        //!< String Constant
25         NODETYPE_INTEGER,       //!< Integer Constant
26         NODETYPE_REAL,  //!< Real Constant
27         
28         NODETYPE_RETURN,        //!< Return from a function (reserved word)
29         NODETYPE_ASSIGN,        //!< Variable assignment operator
30         NODETYPE_FUNCTIONCALL,  //!< Call a function
31         
32         NODETYPE_LOGICALAND,    //!< Logical AND operator
33         NODETYPE_LOGICALOR,     //!< Logical OR operator
34         NODETYPE_LOGICALXOR,    //!< Logical XOR operator
35         
36         NODETYPE_EQUALS,        //!< Comparison Equals
37         NODETYPE_LESSTHAN,      //!< Comparison Less Than
38         NODETYPE_GREATERTHAN,   //!< Comparison Greater Than
39         
40         NODETYPE_BWAND, //!< Bitwise AND
41         NODETYPE_BWOR,  //!< Bitwise OR
42         NODETYPE_BWXOR, //!< Bitwise XOR
43         
44         NODETYPE_BITSHIFTLEFT,  //!< Bitwise Shift Left (Grow)
45         NODETYPE_BITSHIFTRIGHT, //!< Bitwise Shift Right (Shrink)
46         NODETYPE_BITROTATELEFT, //!< Bitwise Rotate Left (Grow)
47         
48         NODETYPE_ADD,   //!< Add
49         NODETYPE_SUBTRACT,      //!< Subtract
50         NODETYPE_MULTIPLY,      //!< Multiply
51         NODETYPE_DIVIDE,        //!< Divide
52         NODETYPE_MODULO,        //!< Modulus
53 };
54
55 struct sSpiderScript
56 {
57         tSpiderVariant  *Variant;
58         tAST_Script     *Script;
59 };
60
61 struct sAST_Script
62 {
63         tAST_Function   *Functions;
64         tAST_Function   *LastFunction;
65 };
66
67 struct sAST_Function
68 {
69         tAST_Function   *Next;
70         char    *Name;
71         tAST_Node       *Code;
72         tAST_Node       *Arguments;     // HACKJOB (Only NODETYPE_VARIABLE is allowed)
73 };
74
75 struct sAST_Node
76 {
77         tAST_Node       *NextSibling;
78         tAST_NodeType   Type;
79         
80         union
81         {
82                 struct {
83                         tAST_Node       *FirstChild;
84                         tAST_Node       *LastChild;
85                 }       Block;
86                 
87                 struct {
88                          int    Operation;
89                         tAST_Node       *Dest;
90                         tAST_Node       *Value;
91                 }       Assign;
92                 
93                 struct {
94                         tAST_Node       *Value;
95                 }       UniOp;
96                 
97                 struct {
98                         tAST_Node       *Left;
99                         tAST_Node       *Right;
100                 }       BinOp;
101                 
102                 struct {
103                          int    Length;
104                         char    Data[];
105                 }       String;
106                 
107                 struct {
108                         tAST_Node       *FirstArg;
109                         tAST_Node       *LastArg;
110                         char    Name[];
111                 }       FunctionCall;
112                 
113                 /**
114                  * \note Used for \a NODETYPE_VARIABLE and \a NODETYPE_CONSTANT
115                  */
116                 struct {
117                         char    _unused;        // Shut GCC up
118                         char    Name[];
119                 }       Variable;
120                 
121                 uint64_t        Integer;
122                 double  Real;
123         };
124 };
125
126 // === FUNCTIONS ===
127 tAST_Script     *AST_NewScript(void);
128
129 tAST_Function   *AST_AppendFunction(tAST_Script *Script, const char *Name);
130 void    AST_AppendFunctionArg(tAST_Function *Function, int Type, tAST_Node *Arg);
131 void    AST_SetFunctionCode(tAST_Function *Function, tAST_Node *Root);
132
133 tAST_Node       *AST_NewString(const char *String, int Length);
134 tAST_Node       *AST_NewInteger(uint64_t Value);
135 tAST_Node       *AST_NewVariable(const char *Name);
136 tAST_Node       *AST_NewConstant(const char *Name);
137 tAST_Node       *AST_NewFunctionCall(const char *Name);
138 void    AST_AppendFunctionCallArg(tAST_Node *Node, tAST_Node *Arg);
139
140 tAST_Node       *AST_NewCodeBlock(void);
141 void    AST_AppendNode(tAST_Node *Parent, tAST_Node *Child);
142 tAST_Node       *AST_NewAssign(int Operation, tAST_Node *Dest, tAST_Node *Value);
143 tAST_Node       *AST_NewBinOp(int Operation, tAST_Node *Left, tAST_Node *Right);
144
145 void    AST_FreeNode(tAST_Node *Node);
146
147 tSpiderVariable *AST_ExecuteNode(tSpiderScript *Script, tAST_Node *Node);
148
149 #endif

UCC git Repository :: git.ucc.asn.au