6 #include <spiderscript.h>
9 typedef enum eAST_NodeTypes tAST_NodeType;
10 typedef struct sAST_Script tAST_Script;
11 typedef struct sAST_Function tAST_Function;
12 typedef struct sAST_Node tAST_Node;
13 typedef struct sAST_BlockState tAST_BlockState;
14 typedef struct sAST_Variable tAST_Variable;
23 NODETYPE_BLOCK, //!< Node Block
26 NODETYPE_VARIABLE, //!< Variable
27 NODETYPE_CONSTANT, //!< Runtime Constant
28 NODETYPE_STRING, //!< String Constant
29 NODETYPE_INTEGER, //!< Integer Constant
30 NODETYPE_REAL, //!< Real Constant
33 NODETYPE_DEFVAR, //!< Define a variable (Variable)
34 NODETYPE_SCOPE, //!< Dereference a Namespace/Class static
35 NODETYPE_ELEMENT, //!< Reference a class attribute
36 NODETYPE_CAST, //!< Cast a value to another (Uniop)
39 NODETYPE_RETURN, //!< Return from a function (reserved word)
40 NODETYPE_BREAK, //!< Break out of a loop
41 NODETYPE_CONTINUE, //!< Next loop iteration
42 NODETYPE_ASSIGN, //!< Variable assignment operator
43 NODETYPE_POSTINC, //!< Post-increment (i++) - Uniop
44 NODETYPE_POSTDEC, //!< Post-decrement (i--) - Uniop
45 NODETYPE_FUNCTIONCALL, //!< Call a function
46 NODETYPE_METHODCALL, //!< Call a class method
47 NODETYPE_CREATEOBJECT, //!< Create an object
50 NODETYPE_IF, //!< Conditional
51 NODETYPE_LOOP, //!< Looping Construct
54 NODETYPE_INDEX, //!< Index into an array
57 NODETYPE_LOGICALNOT, //!< Logical NOT operator
58 NODETYPE_LOGICALAND, //!< Logical AND operator
59 NODETYPE_LOGICALOR, //!< Logical OR operator
60 NODETYPE_LOGICALXOR, //!< Logical XOR operator
62 NODETYPE_EQUALS, //!< Comparison Equals
63 NODETYPE_NOTEQUALS, //!< Comparison Not Equals
64 NODETYPE_LESSTHAN, //!< Comparison Less Than
65 NODETYPE_LESSTHANEQUAL, //!< Comparison Less Than or Equal
66 NODETYPE_GREATERTHAN, //!< Comparison Greater Than
67 NODETYPE_GREATERTHANEQUAL, //!< Comparison Greater Than or Equal
69 NODETYPE_BWNOT, //!< Bitwise NOT
70 NODETYPE_BWAND, //!< Bitwise AND
71 NODETYPE_BWOR, //!< Bitwise OR
72 NODETYPE_BWXOR, //!< Bitwise XOR
74 NODETYPE_BITSHIFTLEFT, //!< Bitwise Shift Left (Grow)
75 NODETYPE_BITSHIFTRIGHT, //!< Bitwise Shift Right (Shrink)
76 NODETYPE_BITROTATELEFT, //!< Bitwise Rotate Left (Grow)
78 NODETYPE_NEGATE, //!< Negagte
79 NODETYPE_ADD, //!< Add
80 NODETYPE_SUBTRACT, //!< Subtract
81 NODETYPE_MULTIPLY, //!< Multiply
82 NODETYPE_DIVIDE, //!< Divide
83 NODETYPE_MODULO, //!< Modulus
88 tAST_Node *NextSibling;
94 void *BlockState; //!< BlockState pointer (for cache integrity)
95 int BlockIdent; //!< Ident (same as above)
96 void *ValueCache; //!< Cached value / pointer
101 tAST_Node *FirstChild;
102 tAST_Node *LastChild;
129 tAST_Node *Condition;
137 tAST_Node *Condition;
138 tAST_Node *Increment;
144 * \note Used for \a NODETYPE_VARIABLE and \a NODETYPE_CONSTANT
147 char _unused; // Shut GCC up
154 } Scope; // Used by NODETYPE_SCOPE and NODETYPE_ELEMENT
158 tAST_Node *LevelSizes;
159 tAST_Node *LevelSizes_Last;
160 tAST_Node *InitialValue;
169 // Used for NODETYPE_REAL, NODETYPE_INTEGER and NODETYPE_STRING
170 tSpiderValue Constant;
175 * \brief Code Block state (stores local variables)
177 struct sAST_BlockState
179 tAST_BlockState *Parent;
180 tSpiderScript *Script; //!< Script
181 tAST_Variable *FirstVar; //!< First variable in the list
182 tSpiderValue *RetVal;
183 tSpiderNamespace *BaseNamespace; //!< Base namespace (for entire block)
184 tSpiderNamespace *CurNamespace; //!< Currently selected namespace
185 int Ident; //!< ID number used for variable lookup caching
186 const char *BreakTarget;
193 int Type; // Only used for static typing
194 tSpiderValue *Object;
199 extern tAST_Script *AST_NewScript(void);
200 extern size_t AST_WriteScript(void *Buffer, tSpiderScript *Script);
201 extern size_t AST_WriteNode(void *Buffer, size_t Offset, tAST_Node *Node);
203 extern int AST_AppendFunction(tSpiderScript *Script, const char *Name, int ReturnType, tAST_Node *FirstArg, tAST_Node *Code);
205 extern tAST_Node *AST_NewNop(tParser *Parser);
207 extern tAST_Node *AST_NewString(tParser *Parser, const char *String, int Length);
208 extern tAST_Node *AST_NewInteger(tParser *Parser, int64_t Value);
209 extern tAST_Node *AST_NewReal(tParser *Parser, double Value);
210 extern tAST_Node *AST_NewVariable(tParser *Parser, const char *Name);
211 extern tAST_Node *AST_NewDefineVar(tParser *Parser, int Type, const char *Name);
212 extern tAST_Node *AST_NewConstant(tParser *Parser, const char *Name);
213 extern tAST_Node *AST_NewClassElement(tParser *Parser, tAST_Node *Object, const char *Name);
215 extern tAST_Node *AST_NewFunctionCall(tParser *Parser, const char *Name);
216 extern tAST_Node *AST_NewCreateObject(tParser *Parser, const char *Name);
217 extern tAST_Node *AST_NewMethodCall(tParser *Parser, tAST_Node *Object, const char *Name);
218 extern void AST_AppendFunctionCallArg(tAST_Node *Node, tAST_Node *Arg);
220 extern tAST_Node *AST_NewCodeBlock(tParser *Parser);
221 extern void AST_AppendNode(tAST_Node *Parent, tAST_Node *Child);
223 extern tAST_Node *AST_NewIf(tParser *Parser, tAST_Node *Condition, tAST_Node *True, tAST_Node *False);
224 extern tAST_Node *AST_NewLoop(tParser *Parser, const char *Tag, tAST_Node *Init, int bPostCheck, tAST_Node *Condition, tAST_Node *Increment, tAST_Node *Code);
226 extern tAST_Node *AST_NewAssign(tParser *Parser, int Operation, tAST_Node *Dest, tAST_Node *Value);
227 extern tAST_Node *AST_NewCast(tParser *Parser, int Target, tAST_Node *Value);
228 extern tAST_Node *AST_NewBinOp(tParser *Parser, int Operation, tAST_Node *Left, tAST_Node *Right);
229 extern tAST_Node *AST_NewUniOp(tParser *Parser, int Operation, tAST_Node *Value);
230 extern tAST_Node *AST_NewBreakout(tParser *Parser, int Type, const char *DestTag);
231 extern tAST_Node *AST_NewScopeDereference(tParser *Parser, const char *Name, tAST_Node *Child);
233 extern void AST_FreeNode(tAST_Node *Node);
236 extern void Object_Dereference(tSpiderValue *Object);
237 extern void Object_Reference(tSpiderValue *Object);
238 extern tSpiderValue *AST_ExecuteNode(tAST_BlockState *Block, tAST_Node *Node);
239 extern tSpiderValue *AST_ExecuteNode_BinOp(tSpiderScript *Script, tAST_Node *Node, int Operation, tSpiderValue *Left, tSpiderValue *Right);
240 extern tSpiderValue *AST_ExecuteNode_UniOp(tSpiderScript *Script, tAST_Node *Node, int Operation, tSpiderValue *Value);