X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Usermode%2FLibraries%2Flibspiderscript.so_src%2Fast.h;h=39ea294712e5d3217319160ae0c8552f40072053;hb=239f2374299c1471a40b1087725b32f3f163d9b3;hp=a9cf1db238a0d7062af72755072bdf94cf2804e9;hpb=9b714e5ea3767470ab5c35f14da67bcb97275021;p=tpg%2Facess2.git diff --git a/Usermode/Libraries/libspiderscript.so_src/ast.h b/Usermode/Libraries/libspiderscript.so_src/ast.h index a9cf1db2..39ea2947 100644 --- a/Usermode/Libraries/libspiderscript.so_src/ast.h +++ b/Usermode/Libraries/libspiderscript.so_src/ast.h @@ -34,6 +34,8 @@ enum eAST_NodeTypes NODETYPE_CAST, //!< Cast a value to another (Uniop) NODETYPE_RETURN, //!< Return from a function (reserved word) + NODETYPE_BREAK, //!< Break out of a loop + NODETYPE_CONTINUE, //!< Next loop iteration NODETYPE_ASSIGN, //!< Variable assignment operator NODETYPE_POSTINC, //!< Post-increment (i++) - Uniop NODETYPE_POSTDEC, //!< Post-decrement (i--) - Uniop @@ -74,29 +76,6 @@ enum eAST_NodeTypes NODETYPE_MODULO, //!< Modulus }; -struct sSpiderScript -{ - tSpiderVariant *Variant; - tAST_Script *Script; - char *CurNamespace; //!< Current namespace prefix (NULL = Root) - No trailing . -}; - -struct sAST_Script -{ - // TODO: Namespaces and Classes - tAST_Function *Functions; - tAST_Function *LastFunction; -}; - -struct sAST_Function -{ - tAST_Function *Next; //!< Next function in list - tAST_Node *Code; //!< Function Code - tAST_Node *Arguments; // HACKJOB (Only NODETYPE_DEFVAR is allowed) - tAST_Node *Arguments_Last; - char Name[]; //!< Function Name -}; - struct sAST_Node { tAST_Node *NextSibling; @@ -105,6 +84,10 @@ struct sAST_Node 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 { @@ -147,11 +130,11 @@ struct sAST_Node tAST_Node *Condition; tAST_Node *Increment; tAST_Node *Code; + char Tag[]; } For; /** - * \note Used for \a NODETYPE_VARIABLE, \a NODETYPE_CONSTANT and - * \a NODETYPE_SCOPE + * \note Used for \a NODETYPE_VARIABLE and \a NODETYPE_CONSTANT */ struct { char _unused; // Shut GCC up @@ -167,6 +150,7 @@ struct sAST_Node int DataType; tAST_Node *LevelSizes; tAST_Node *LevelSizes_Last; + tAST_Node *InitialValue; char Name[]; } DefVar; @@ -175,13 +159,8 @@ struct sAST_Node tAST_Node *Value; } Cast; - struct { - int Length; - char Data[]; - } String; - - uint64_t Integer; - double Real; + // Used for NODETYPE_REAL, NODETYPE_INTEGER and NODETYPE_STRING + tSpiderValue Constant; }; }; @@ -196,6 +175,9 @@ struct sAST_BlockState tSpiderValue *RetVal; tSpiderNamespace *BaseNamespace; //!< Base namespace (for entire block) tSpiderNamespace *CurNamespace; //!< Currently selected namespace + int Ident; //!< ID number used for variable lookup caching + const char *BreakTarget; + int BreakType; }; struct sAST_Variable @@ -208,12 +190,10 @@ struct sAST_Variable // === FUNCTIONS === extern tAST_Script *AST_NewScript(void); -extern size_t AST_WriteScript(void *Buffer, tAST_Script *Script); +extern size_t AST_WriteScript(void *Buffer, tSpiderScript *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 void AST_AppendFunctionArg(tAST_Function *Function, tAST_Node *Arg); -extern void AST_SetFunctionCode(tAST_Function *Function, tAST_Node *Root); +extern int AST_AppendFunction(tSpiderScript *Script, const char *Name, int ReturnType, tAST_Node *FirstArg, tAST_Node *Code); extern tAST_Node *AST_NewNop(tParser *Parser); @@ -234,12 +214,13 @@ extern tAST_Node *AST_NewCodeBlock(tParser *Parser); extern void AST_AppendNode(tAST_Node *Parent, tAST_Node *Child); 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_NewLoop(tParser *Parser, const char *Tag, 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 tAST_Node *AST_NewBreakout(tParser *Parser, int Type, const char *DestTag); extern tAST_Node *AST_NewScopeDereference(tParser *Parser, const char *Name, tAST_Node *Child); extern void AST_FreeNode(tAST_Node *Node); @@ -248,5 +229,7 @@ extern void AST_FreeNode(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); +extern tSpiderValue *AST_ExecuteNode_BinOp(tSpiderScript *Script, tAST_Node *Node, int Operation, tSpiderValue *Left, tSpiderValue *Right); +extern tSpiderValue *AST_ExecuteNode_UniOp(tSpiderScript *Script, tAST_Node *Node, int Operation, tSpiderValue *Value); #endif