X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Usermode%2FLibraries%2Flibspiderscript.so_src%2Fast.h;h=565c94aabdd09736d00948246ed7fa6ef8501d3c;hb=fe313c1dda9bd0e062f5ce88c3d990199799aa1b;hp=9179563626f4b3e001857e956b8c17a3268864bc;hpb=1529dadb6c2170bf9899fbde46d06a3d9a392b52;p=tpg%2Facess2.git diff --git a/Usermode/Libraries/libspiderscript.so_src/ast.h b/Usermode/Libraries/libspiderscript.so_src/ast.h index 91795636..565c94aa 100644 --- a/Usermode/Libraries/libspiderscript.so_src/ast.h +++ b/Usermode/Libraries/libspiderscript.so_src/ast.h @@ -4,6 +4,7 @@ #define _AST_H_ #include +#include "tokens.h" typedef enum eAST_NodeTypes tAST_NodeType; typedef struct sAST_Script tAST_Script; @@ -34,6 +35,9 @@ enum eAST_NodeTypes NODETYPE_ASSIGN, //!< Variable assignment operator NODETYPE_FUNCTIONCALL, //!< Call a function + NODETYPE_IF, //!< Conditional + NODETYPE_LOOP, //!< Looping Construct + NODETYPE_INDEX, //!< Index into an array NODETYPE_LOGICALAND, //!< Logical AND operator @@ -86,6 +90,9 @@ struct sAST_Node tAST_Node *NextSibling; tAST_NodeType Type; + const char *File; + int Line; + union { struct { @@ -108,17 +115,26 @@ struct sAST_Node tAST_Node *Right; } BinOp; - struct { - int Length; - char Data[]; - } String; - struct { tAST_Node *FirstArg; tAST_Node *LastArg; char Name[]; } FunctionCall; + struct { + tAST_Node *Condition; + tAST_Node *True; + tAST_Node *False; + } If; + + struct { + tAST_Node *Init; + int bCheckAfter; + tAST_Node *Condition; + tAST_Node *Increment; + tAST_Node *Code; + } For; + /** * \note Used for \a NODETYPE_VARIABLE and \a NODETYPE_CONSTANT */ @@ -140,6 +156,11 @@ struct sAST_Node tAST_Node *Value; } Cast; + struct { + int Length; + char Data[]; + } String; + uint64_t Integer; double Real; }; @@ -153,13 +174,14 @@ struct sAST_BlockState tAST_BlockState *Parent; tSpiderScript *Script; //!< Script tAST_Variable *FirstVar; //!< First variable in the list + tSpiderValue *RetVal; }; struct sAST_Variable { tAST_Variable *Next; int Type; // Only used for static typing - tSpiderObject *Object; + tSpiderValue *Object; char Name[]; }; @@ -169,24 +191,30 @@ extern tAST_Script *AST_NewScript(void); extern tAST_Function *AST_AppendFunction(tAST_Script *Script, const char *Name); extern void AST_AppendFunctionArg(tAST_Function *Function, tAST_Node *Arg); extern void AST_SetFunctionCode(tAST_Function *Function, tAST_Node *Root); - -extern tAST_Node *AST_NewString(const char *String, int Length); -extern tAST_Node *AST_NewInteger(uint64_t Value); -extern tAST_Node *AST_NewVariable(const char *Name); -extern tAST_Node *AST_NewDefineVar(int Type, const char *Name); -extern tAST_Node *AST_NewConstant(const char *Name); -extern tAST_Node *AST_NewFunctionCall(const char *Name); +extern tAST_Node *AST_NewString(tParser *Parser, const char *String, int Length); +extern tAST_Node *AST_NewInteger(tParser *Parser, uint64_t Value); +extern tAST_Node *AST_NewVariable(tParser *Parser, const char *Name); +extern tAST_Node *AST_NewDefineVar(tParser *Parser, int Type, const char *Name); +extern tAST_Node *AST_NewConstant(tParser *Parser, const char *Name); +extern tAST_Node *AST_NewFunctionCall(tParser *Parser, const char *Name); extern void AST_AppendFunctionCallArg(tAST_Node *Node, tAST_Node *Arg); extern tAST_Node *AST_NewCodeBlock(void); extern void AST_AppendNode(tAST_Node *Parent, tAST_Node *Child); -extern tAST_Node *AST_NewAssign(int Operation, tAST_Node *Dest, tAST_Node *Value); -extern tAST_Node *AST_NewBinOp(int Operation, tAST_Node *Left, tAST_Node *Right); -extern tAST_Node *AST_NewUniOp(int Operation, tAST_Node *Value); + +extern tAST_Node *AST_NewIf(tParser *Parser, tAST_Node *Condition, tAST_Node *True, tAST_Node *False); +extern tAST_Node *AST_NewLoop(tParser *Parser, tAST_Node *Init, int bPostCheck, tAST_Node *Condition, tAST_Node *Increment, tAST_Node *Code); + +extern tAST_Node *AST_NewAssign(tParser *Parser, int Operation, tAST_Node *Dest, tAST_Node *Value); +extern tAST_Node *AST_NewCast(tParser *Parser, int Target, tAST_Node *Value); +extern tAST_Node *AST_NewBinOp(tParser *Parser, int Operation, tAST_Node *Left, tAST_Node *Right); +extern tAST_Node *AST_NewUniOp(tParser *Parser, int Operation, tAST_Node *Value); extern void AST_FreeNode(tAST_Node *Node); // exec_ast.h -extern tSpiderObject *AST_ExecuteNode(tAST_BlockState *Block, tAST_Node *Node); +extern void Object_Dereference(tSpiderValue *Object); +extern void Object_Reference(tSpiderValue *Object); +extern tSpiderValue *AST_ExecuteNode(tAST_BlockState *Block, tAST_Node *Node); #endif