X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Usermode%2FLibraries%2Flibspiderscript.so_src%2Fast.h;h=06d3333354d3f01d646be537f5f1a0c6c504b0a2;hb=d2ef25f69dfb16c2510a9b305b6fa288548af8bc;hp=8b9c25b05ddf781805b389723a2293c5d244dce0;hpb=7eab89f95c3ea818686482a69a2d37ce0cb68c62;p=tpg%2Facess2.git diff --git a/Usermode/Libraries/libspiderscript.so_src/ast.h b/Usermode/Libraries/libspiderscript.so_src/ast.h index 8b9c25b0..06d33333 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; @@ -28,25 +29,35 @@ enum eAST_NodeTypes NODETYPE_REAL, //!< Real Constant NODETYPE_DEFVAR, //!< Define a variable (Variable) + NODETYPE_SCOPE, //!< Dereference a Namespace/Class static + NODETYPE_ELEMENT, //!< Reference a class attribute NODETYPE_CAST, //!< Cast a value to another (Uniop) NODETYPE_RETURN, //!< Return from a function (reserved word) NODETYPE_ASSIGN, //!< Variable assignment operator + NODETYPE_POSTINC, //!< Post-increment (i++) - Uniop + NODETYPE_POSTDEC, //!< Post-decrement (i--) - Uniop NODETYPE_FUNCTIONCALL, //!< Call a function + NODETYPE_METHODCALL, //!< Call a class method + NODETYPE_CREATEOBJECT, //!< Create an object NODETYPE_IF, //!< Conditional NODETYPE_LOOP, //!< Looping Construct NODETYPE_INDEX, //!< Index into an array + NODETYPE_LOGICALNOT, //!< Logical NOT operator NODETYPE_LOGICALAND, //!< Logical AND operator NODETYPE_LOGICALOR, //!< Logical OR operator NODETYPE_LOGICALXOR, //!< Logical XOR operator NODETYPE_EQUALS, //!< Comparison Equals NODETYPE_LESSTHAN, //!< Comparison Less Than + NODETYPE_LESSTHANEQUAL, //!< Comparison Less Than or Equal NODETYPE_GREATERTHAN, //!< Comparison Greater Than + NODETYPE_GREATERTHANEQUAL, //!< Comparison Greater Than or Equal + NODETYPE_BWNOT, //!< Bitwise NOT NODETYPE_BWAND, //!< Bitwise AND NODETYPE_BWOR, //!< Bitwise OR NODETYPE_BWXOR, //!< Bitwise XOR @@ -55,6 +66,7 @@ enum eAST_NodeTypes NODETYPE_BITSHIFTRIGHT, //!< Bitwise Shift Right (Shrink) NODETYPE_BITROTATELEFT, //!< Bitwise Rotate Left (Grow) + NODETYPE_NEGATE, //!< Negagte NODETYPE_ADD, //!< Add NODETYPE_SUBTRACT, //!< Subtract NODETYPE_MULTIPLY, //!< Multiply @@ -71,6 +83,7 @@ struct sSpiderScript struct sAST_Script { + // TODO: Namespaces and Classes tAST_Function *Functions; tAST_Function *LastFunction; }; @@ -78,6 +91,7 @@ struct sAST_Script struct sAST_Function { tAST_Function *Next; //!< Next function in list + int ReturnType; tAST_Node *Code; //!< Function Code tAST_Node *Arguments; // HACKJOB (Only NODETYPE_DEFVAR is allowed) tAST_Node *Arguments_Last; @@ -89,6 +103,13 @@ struct sAST_Node tAST_Node *NextSibling; tAST_NodeType Type; + const char *File; + int Line; + + void *BlockState; //!< BlockState pointer (for cache integrity) + int BlockIdent; //!< Ident (same as above) + void *ValueCache; //!< Cached value / pointer + union { struct { @@ -112,13 +133,10 @@ struct sAST_Node } BinOp; struct { - int Length; - char Data[]; - } String; - - struct { + tAST_Node *Object; tAST_Node *FirstArg; tAST_Node *LastArg; + int NumArgs; char Name[]; } FunctionCall; @@ -137,18 +155,24 @@ struct sAST_Node } For; /** - * \note Used for \a NODETYPE_VARIABLE and \a NODETYPE_CONSTANT + * \note Used for \a NODETYPE_VARIABLE, \a NODETYPE_CONSTANT and + * \a NODETYPE_SCOPE */ struct { char _unused; // Shut GCC up char Name[]; } Variable; + struct { + tAST_Node *Element; + char Name[]; + } Scope; // Used by NODETYPE_SCOPE and NODETYPE_ELEMENT + struct { int DataType; - int Depth; tAST_Node *LevelSizes; tAST_Node *LevelSizes_Last; + tAST_Node *InitialValue; char Name[]; } DefVar; @@ -157,8 +181,8 @@ struct sAST_Node tAST_Node *Value; } Cast; - uint64_t Integer; - double Real; + // Used for NODETYPE_REAL, NODETYPE_INTEGER and NODETYPE_STRING + tSpiderValue Constant; }; }; @@ -171,6 +195,9 @@ struct sAST_BlockState tSpiderScript *Script; //!< Script tAST_Variable *FirstVar; //!< First variable in the list tSpiderValue *RetVal; + tSpiderNamespace *BaseNamespace; //!< Base namespace (for entire block) + tSpiderNamespace *CurNamespace; //!< Currently selected namespace + int Ident; }; struct sAST_Variable @@ -183,27 +210,39 @@ struct sAST_Variable // === FUNCTIONS === extern tAST_Script *AST_NewScript(void); +extern size_t AST_WriteScript(void *Buffer, tAST_Script *Script); +extern size_t AST_WriteNode(void *Buffer, size_t Offset, tAST_Node *Node); -extern tAST_Function *AST_AppendFunction(tAST_Script *Script, const char *Name); +extern tAST_Function *AST_AppendFunction(tAST_Script *Script, const char *Name, int ReturnType); 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_NewNop(tParser *Parser); + +extern tAST_Node *AST_NewString(tParser *Parser, const char *String, int Length); +extern tAST_Node *AST_NewInteger(tParser *Parser, int64_t Value); +extern tAST_Node *AST_NewReal(tParser *Parser, double 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_NewClassElement(tParser *Parser, tAST_Node *Object, const char *Name); + +extern tAST_Node *AST_NewFunctionCall(tParser *Parser, const char *Name); +extern tAST_Node *AST_NewCreateObject(tParser *Parser, const char *Name); +extern tAST_Node *AST_NewMethodCall(tParser *Parser, tAST_Node *Object, const char *Name); extern void AST_AppendFunctionCallArg(tAST_Node *Node, tAST_Node *Arg); -extern tAST_Node *AST_NewCodeBlock(void); +extern tAST_Node *AST_NewCodeBlock(tParser *Parser); extern void AST_AppendNode(tAST_Node *Parent, tAST_Node *Child); -extern tAST_Node *AST_NewIf(tAST_Node *Condition, tAST_Node *True, tAST_Node *False); +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(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_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 tAST_Node *AST_NewScopeDereference(tParser *Parser, const char *Name, tAST_Node *Child); extern void AST_FreeNode(tAST_Node *Node);