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
25 NODETYPE_VARIABLE, //!< Variable
26 NODETYPE_CONSTANT, //!< Runtime Constant
27 NODETYPE_STRING, //!< String Constant
28 NODETYPE_INTEGER, //!< Integer Constant
29 NODETYPE_REAL, //!< Real Constant
31 NODETYPE_DEFVAR, //!< Define a variable (Variable)
32 NODETYPE_CAST, //!< Cast a value to another (Uniop)
34 NODETYPE_RETURN, //!< Return from a function (reserved word)
35 NODETYPE_ASSIGN, //!< Variable assignment operator
36 NODETYPE_FUNCTIONCALL, //!< Call a function
38 NODETYPE_IF, //!< Conditional
39 NODETYPE_LOOP, //!< Looping Construct
41 NODETYPE_INDEX, //!< Index into an array
43 NODETYPE_LOGICALAND, //!< Logical AND operator
44 NODETYPE_LOGICALOR, //!< Logical OR operator
45 NODETYPE_LOGICALXOR, //!< Logical XOR operator
47 NODETYPE_EQUALS, //!< Comparison Equals
48 NODETYPE_LESSTHAN, //!< Comparison Less Than
49 NODETYPE_GREATERTHAN, //!< Comparison Greater Than
51 NODETYPE_BWAND, //!< Bitwise AND
52 NODETYPE_BWOR, //!< Bitwise OR
53 NODETYPE_BWXOR, //!< Bitwise XOR
55 NODETYPE_BITSHIFTLEFT, //!< Bitwise Shift Left (Grow)
56 NODETYPE_BITSHIFTRIGHT, //!< Bitwise Shift Right (Shrink)
57 NODETYPE_BITROTATELEFT, //!< Bitwise Rotate Left (Grow)
59 NODETYPE_ADD, //!< Add
60 NODETYPE_SUBTRACT, //!< Subtract
61 NODETYPE_MULTIPLY, //!< Multiply
62 NODETYPE_DIVIDE, //!< Divide
63 NODETYPE_MODULO, //!< Modulus
68 tSpiderVariant *Variant;
70 char *CurNamespace; //!< Current namespace prefix (NULL = Root) - No trailing .
75 tAST_Function *Functions;
76 tAST_Function *LastFunction;
81 tAST_Function *Next; //!< Next function in list
82 tAST_Node *Code; //!< Function Code
83 tAST_Node *Arguments; // HACKJOB (Only NODETYPE_DEFVAR is allowed)
84 tAST_Node *Arguments_Last;
85 char Name[]; //!< Function Name
90 tAST_Node *NextSibling;
99 tAST_Node *FirstChild;
100 tAST_Node *LastChild;
125 tAST_Node *Condition;
133 tAST_Node *Condition;
134 tAST_Node *Increment;
139 * \note Used for \a NODETYPE_VARIABLE and \a NODETYPE_CONSTANT
142 char _unused; // Shut GCC up
149 tAST_Node *LevelSizes;
150 tAST_Node *LevelSizes_Last;
170 * \brief Code Block state (stores local variables)
172 struct sAST_BlockState
174 tAST_BlockState *Parent;
175 tSpiderScript *Script; //!< Script
176 tAST_Variable *FirstVar; //!< First variable in the list
177 tSpiderValue *RetVal;
183 int Type; // Only used for static typing
184 tSpiderValue *Object;
189 extern tAST_Script *AST_NewScript(void);
191 extern tAST_Function *AST_AppendFunction(tAST_Script *Script, const char *Name);
192 extern void AST_AppendFunctionArg(tAST_Function *Function, tAST_Node *Arg);
193 extern void AST_SetFunctionCode(tAST_Function *Function, tAST_Node *Root);
194 extern tAST_Node *AST_NewString(tParser *Parser, const char *String, int Length);
195 extern tAST_Node *AST_NewInteger(tParser *Parser, uint64_t Value);
196 extern tAST_Node *AST_NewVariable(tParser *Parser, const char *Name);
197 extern tAST_Node *AST_NewDefineVar(tParser *Parser, int Type, const char *Name);
198 extern tAST_Node *AST_NewConstant(tParser *Parser, const char *Name);
199 extern tAST_Node *AST_NewFunctionCall(tParser *Parser, const char *Name);
200 extern void AST_AppendFunctionCallArg(tAST_Node *Node, tAST_Node *Arg);
202 extern tAST_Node *AST_NewCodeBlock(void);
203 extern void AST_AppendNode(tAST_Node *Parent, tAST_Node *Child);
205 extern tAST_Node *AST_NewIf(tParser *Parser, tAST_Node *Condition, tAST_Node *True, tAST_Node *False);
206 extern tAST_Node *AST_NewLoop(tParser *Parser, tAST_Node *Init, int bPostCheck, tAST_Node *Condition, tAST_Node *Increment, tAST_Node *Code);
208 extern tAST_Node *AST_NewAssign(tParser *Parser, int Operation, tAST_Node *Dest, tAST_Node *Value);
209 extern tAST_Node *AST_NewCast(tParser *Parser, int Target, tAST_Node *Value);
210 extern tAST_Node *AST_NewBinOp(tParser *Parser, int Operation, tAST_Node *Left, tAST_Node *Right);
211 extern tAST_Node *AST_NewUniOp(tParser *Parser, int Operation, tAST_Node *Value);
213 extern void AST_FreeNode(tAST_Node *Node);
216 extern void Object_Dereference(tSpiderValue *Object);
217 extern void Object_Reference(tSpiderValue *Object);
218 extern tSpiderValue *AST_ExecuteNode(tAST_BlockState *Block, tAST_Node *Node);