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_INDEX, //!< Index into an array
39 NODETYPE_LOGICALAND, //!< Logical AND operator
40 NODETYPE_LOGICALOR, //!< Logical OR operator
41 NODETYPE_LOGICALXOR, //!< Logical XOR operator
43 NODETYPE_EQUALS, //!< Comparison Equals
44 NODETYPE_LESSTHAN, //!< Comparison Less Than
45 NODETYPE_GREATERTHAN, //!< Comparison Greater Than
47 NODETYPE_BWAND, //!< Bitwise AND
48 NODETYPE_BWOR, //!< Bitwise OR
49 NODETYPE_BWXOR, //!< Bitwise XOR
51 NODETYPE_BITSHIFTLEFT, //!< Bitwise Shift Left (Grow)
52 NODETYPE_BITSHIFTRIGHT, //!< Bitwise Shift Right (Shrink)
53 NODETYPE_BITROTATELEFT, //!< Bitwise Rotate Left (Grow)
55 NODETYPE_ADD, //!< Add
56 NODETYPE_SUBTRACT, //!< Subtract
57 NODETYPE_MULTIPLY, //!< Multiply
58 NODETYPE_DIVIDE, //!< Divide
59 NODETYPE_MODULO, //!< Modulus
64 tSpiderVariant *Variant;
66 char *CurNamespace; //!< Current namespace prefix (NULL = Root) - No trailing .
71 tAST_Function *Functions;
72 tAST_Function *LastFunction;
77 tAST_Function *Next; //!< Next function in list
78 tAST_Node *Code; //!< Function Code
79 tAST_Node *Arguments; // HACKJOB (Only NODETYPE_DEFVAR is allowed)
80 tAST_Node *Arguments_Last;
81 char Name[]; //!< Function Name
86 tAST_Node *NextSibling;
92 tAST_Node *FirstChild;
123 * \note Used for \a NODETYPE_VARIABLE and \a NODETYPE_CONSTANT
126 char _unused; // Shut GCC up
133 tAST_Node *LevelSizes;
134 tAST_Node *LevelSizes_Last;
149 * \brief Code Block state (stores local variables)
151 struct sAST_BlockState
153 tAST_BlockState *Parent;
154 tSpiderScript *Script; //!< Script
155 tAST_Variable *FirstVar; //!< First variable in the list
161 int Type; // Only used for static typing
162 tSpiderObject *Object;
167 extern tAST_Script *AST_NewScript(void);
169 extern tAST_Function *AST_AppendFunction(tAST_Script *Script, const char *Name);
170 extern void AST_AppendFunctionArg(tAST_Function *Function, tAST_Node *Arg);
171 extern void AST_SetFunctionCode(tAST_Function *Function, tAST_Node *Root);
173 extern tAST_Node *AST_NewString(const char *String, int Length);
174 extern tAST_Node *AST_NewInteger(uint64_t Value);
175 extern tAST_Node *AST_NewVariable(const char *Name);
176 extern tAST_Node *AST_NewDefineVar(int Type, const char *Name);
177 extern tAST_Node *AST_NewConstant(const char *Name);
178 extern tAST_Node *AST_NewFunctionCall(const char *Name);
179 extern void AST_AppendFunctionCallArg(tAST_Node *Node, tAST_Node *Arg);
181 extern tAST_Node *AST_NewCodeBlock(void);
182 extern void AST_AppendNode(tAST_Node *Parent, tAST_Node *Child);
183 extern tAST_Node *AST_NewAssign(int Operation, tAST_Node *Dest, tAST_Node *Value);
184 extern tAST_Node *AST_NewBinOp(int Operation, tAST_Node *Left, tAST_Node *Right);
185 extern tAST_Node *AST_NewUniOp(int Operation, tAST_Node *Value);
187 extern void AST_FreeNode(tAST_Node *Node);
190 extern tSpiderObject *AST_ExecuteNode(tAST_BlockState *Block, tAST_Node *Node);