6 #include <spiderscript.h>
8 typedef enum eAST_NodeTypes tAST_NodeType;
9 typedef struct sAST_Script tAST_Script;
10 typedef struct sAST_Function tAST_Function;
11 typedef struct sAST_Node tAST_Node;
12 typedef struct sAST_BlockState tAST_BlockState;
13 typedef struct sAST_Variable tAST_Variable;
22 NODETYPE_BLOCK, //!< Node Block
24 NODETYPE_VARIABLE, //!< Variable
25 NODETYPE_CONSTANT, //!< Runtime Constant
26 NODETYPE_STRING, //!< String Constant
27 NODETYPE_INTEGER, //!< Integer Constant
28 NODETYPE_REAL, //!< Real Constant
30 NODETYPE_DEFVAR, //!< Define a variable (Variable)
31 NODETYPE_CAST, //!< Cast a value to another (Uniop)
33 NODETYPE_RETURN, //!< Return from a function (reserved word)
34 NODETYPE_ASSIGN, //!< Variable assignment operator
35 NODETYPE_FUNCTIONCALL, //!< Call a function
37 NODETYPE_IF, //!< Conditional
38 NODETYPE_LOOP, //!< Looping Construct
40 NODETYPE_INDEX, //!< Index into an array
42 NODETYPE_LOGICALAND, //!< Logical AND operator
43 NODETYPE_LOGICALOR, //!< Logical OR operator
44 NODETYPE_LOGICALXOR, //!< Logical XOR operator
46 NODETYPE_EQUALS, //!< Comparison Equals
47 NODETYPE_LESSTHAN, //!< Comparison Less Than
48 NODETYPE_GREATERTHAN, //!< Comparison Greater Than
50 NODETYPE_BWAND, //!< Bitwise AND
51 NODETYPE_BWOR, //!< Bitwise OR
52 NODETYPE_BWXOR, //!< Bitwise XOR
54 NODETYPE_BITSHIFTLEFT, //!< Bitwise Shift Left (Grow)
55 NODETYPE_BITSHIFTRIGHT, //!< Bitwise Shift Right (Shrink)
56 NODETYPE_BITROTATELEFT, //!< Bitwise Rotate Left (Grow)
58 NODETYPE_ADD, //!< Add
59 NODETYPE_SUBTRACT, //!< Subtract
60 NODETYPE_MULTIPLY, //!< Multiply
61 NODETYPE_DIVIDE, //!< Divide
62 NODETYPE_MODULO, //!< Modulus
67 tSpiderVariant *Variant;
69 char *CurNamespace; //!< Current namespace prefix (NULL = Root) - No trailing .
74 tAST_Function *Functions;
75 tAST_Function *LastFunction;
80 tAST_Function *Next; //!< Next function in list
81 tAST_Node *Code; //!< Function Code
82 tAST_Node *Arguments; // HACKJOB (Only NODETYPE_DEFVAR is allowed)
83 tAST_Node *Arguments_Last;
84 char Name[]; //!< Function Name
89 tAST_Node *NextSibling;
95 tAST_Node *FirstChild;
126 tAST_Node *Condition;
134 tAST_Node *Condition;
135 tAST_Node *Increment;
140 * \note Used for \a NODETYPE_VARIABLE and \a NODETYPE_CONSTANT
143 char _unused; // Shut GCC up
150 tAST_Node *LevelSizes;
151 tAST_Node *LevelSizes_Last;
166 * \brief Code Block state (stores local variables)
168 struct sAST_BlockState
170 tAST_BlockState *Parent;
171 tSpiderScript *Script; //!< Script
172 tAST_Variable *FirstVar; //!< First variable in the list
173 tSpiderValue *RetVal;
179 int Type; // Only used for static typing
180 tSpiderValue *Object;
185 extern tAST_Script *AST_NewScript(void);
187 extern tAST_Function *AST_AppendFunction(tAST_Script *Script, const char *Name);
188 extern void AST_AppendFunctionArg(tAST_Function *Function, tAST_Node *Arg);
189 extern void AST_SetFunctionCode(tAST_Function *Function, tAST_Node *Root);
191 extern tAST_Node *AST_NewString(const char *String, int Length);
192 extern tAST_Node *AST_NewInteger(uint64_t Value);
193 extern tAST_Node *AST_NewVariable(const char *Name);
194 extern tAST_Node *AST_NewDefineVar(int Type, const char *Name);
195 extern tAST_Node *AST_NewConstant(const char *Name);
196 extern tAST_Node *AST_NewFunctionCall(const char *Name);
197 extern void AST_AppendFunctionCallArg(tAST_Node *Node, tAST_Node *Arg);
199 extern tAST_Node *AST_NewCodeBlock(void);
200 extern void AST_AppendNode(tAST_Node *Parent, tAST_Node *Child);
202 extern tAST_Node *AST_NewIf(tAST_Node *Condition, tAST_Node *True, tAST_Node *False);
204 extern tAST_Node *AST_NewAssign(int Operation, tAST_Node *Dest, tAST_Node *Value);
205 extern tAST_Node *AST_NewBinOp(int Operation, tAST_Node *Left, tAST_Node *Right);
206 extern tAST_Node *AST_NewUniOp(int Operation, tAST_Node *Value);
208 extern void AST_FreeNode(tAST_Node *Node);
211 extern tSpiderValue *AST_ExecuteNode(tAST_BlockState *Block, tAST_Node *Node);