X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Usermode%2Finclude%2Fspiderscript.h;h=e0497305523d6dffc2cbc590cb14e78c72f0fc54;hb=f12d3444d2efeae97f8a4fc7ecf65b23087a653a;hp=dc62a23d6a21fb6e2c5f1df4fc396e3e935ac8e8;hpb=17c447e4977d83c1b6aadcb80f4542b4802e9b21;p=tpg%2Facess2.git diff --git a/Usermode/include/spiderscript.h b/Usermode/include/spiderscript.h index dc62a23d..e0497305 100644 --- a/Usermode/include/spiderscript.h +++ b/Usermode/include/spiderscript.h @@ -14,6 +14,7 @@ typedef struct sSpiderScript tSpiderScript; typedef struct sSpiderVariant tSpiderVariant; +typedef struct sSpiderNamespace tSpiderNamespace; typedef struct sSpiderFunction tSpiderFunction; typedef struct sSpiderValue tSpiderValue; typedef struct sSpiderObjectDef tSpiderObjectDef; @@ -50,7 +51,7 @@ enum eSpiderScript_DataTypes */ SS_DATATYPE_OBJECT, /** - * \brief Array data type + * \brief Array data type (invalid when using static typing) */ SS_DATATYPE_ARRAY, /** @@ -64,6 +65,50 @@ enum eSpiderScript_DataTypes NUM_SS_DATATYPES }; +#define SS_MAKEARRAY(_type) ((_type) + 0x10000) +#define SS_DOWNARRAY(_type) ((_type) - 0x10000) +#define SS_GETARRAYDEPTH(_type) ((_type) >> 16) + +enum eSpiderValueOps +{ + SS_VALUEOP_NOP, + + SS_VALUEOP_ADD, + SS_VALUEOP_SUBTRACT, + SS_VALUEOP_NEGATE, + SS_VALUEOP_MULIPLY, + SS_VALUEOP_DIVIDE, + SS_VALUEOP_MODULO, + + SS_VALUEOP_BITNOT, + SS_VALUEOP_BITAND, + SS_VALUEOP_BITOR, + SS_VALUEOP_BITXOR, + + SS_VALUEOP_SHIFTLEFT, + SS_VALUEOP_SHIFTRIGHT, + SS_VALUEOP_ROTATELEFT +}; + +/** + * \brief Namespace definition + */ +struct sSpiderNamespace +{ + tSpiderNamespace *Next; + + tSpiderNamespace *FirstChild; + + tSpiderFunction *Functions; + + tSpiderObjectDef *Classes; + + int NConstants; //!< Number of constants + tSpiderValue *Constants; //!< Number of constants + + const char Name[]; +}; + /** * \brief Variant of SpiderScript */ @@ -71,12 +116,15 @@ struct sSpiderVariant { const char *Name; // Just for debug - int bDyamicTyped; //!< Use static typing + int bDyamicTyped; //!< Use dynamic typing + int bImplicitCasts; //!< Allow implicit casts (casts to lefthand side) tSpiderFunction *Functions; //!< Functions (Linked List) int NConstants; //!< Number of constants tSpiderValue *Constants; //!< Number of constants + + tSpiderNamespace RootNamespace; }; /** @@ -88,7 +136,7 @@ struct sSpiderValue int ReferenceCount; //!< Reference count union { - uint64_t Integer; //!< Integer data + int64_t Integer; //!< Integer data double Real; //!< Real Number data /** * \brief String data @@ -133,16 +181,16 @@ struct sSpiderObjectDef /** * \brief Object type name */ - const char* const Name; + const char * const Name; /** * \brief Construct an instance of the object * \param NArgs Number of arguments - * \param Args Argument count + * \param Args Argument array * \return Pointer to an object instance (which must be fully valid) * \retval NULL Invalid parameter (usually, actually just a NULL value) * \retval ERRPTR Invalid parameter count */ - tSpiderObject *(*Constructor)(int NArgs, tSpiderValue *Args); + tSpiderObject *(*Constructor)(int NArgs, tSpiderValue **Args); /** * \brief Clean up and destroy the object @@ -152,17 +200,15 @@ struct sSpiderObjectDef */ void (*Destructor)(tSpiderObject *This); + tSpiderFunction *Methods; //!< Method Definitions (linked list) + int NAttributes; //!< Number of attributes //! Attribute definitions struct { const char *Name; //!< Attribute Name int bReadOnly; //!< Allow writes to the attribute? - } *AttributeDefs; - - - int NMethods; //!< Number of methods - tSpiderFunction *Methods; //!< Method Definitions + } AttributeDefs[]; }; /** @@ -171,7 +217,7 @@ struct sSpiderObjectDef struct sSpiderObject { tSpiderObjectDef *Type; //!< Object Type - int NReferences; //!< Number of references + int ReferenceCount; //!< Number of references void *OpaqueData; //!< Pointer to the end of the \a Attributes array tSpiderValue *Attributes[]; //!< Attribute Array }; @@ -194,6 +240,12 @@ struct sSpiderFunction * \brief Function handler */ tSpiderValue *(*Handler)(tSpiderScript *Script, int nParams, tSpiderValue **Parameters); + + /** + * \brief What type is returned + */ + int ReturnType; + /** * \brief Argument types * @@ -215,32 +267,64 @@ struct sSpiderFunction */ extern tSpiderScript *SpiderScript_ParseFile(tSpiderVariant *Variant, const char *Filename); /** - * \brief Execute a method from a script + * \brief Execute a function from a script * \param Script Script to run * \param Function Name of function to run ("" for the 'main') * \return Return value */ +extern tSpiderValue *SpiderScript_ExecuteFunction(tSpiderScript *Script, + const char *Function, const char *DefaultNamespaces[], + int NArguments, tSpiderValue **Arguments, + void **FunctionIdent + ); +/** + * \brief Execute an object method + */ extern tSpiderValue *SpiderScript_ExecuteMethod(tSpiderScript *Script, - const char *Function, + tSpiderObject *Object, const char *MethodName, + int NArguments, tSpiderValue **Arguments + ); +/** + * \brief Creates an object instance + */ +extern tSpiderValue *SpiderScript_CreateObject(tSpiderScript *Script, + const char *ClassName, const char *DefaultNamespaces[], int NArguments, tSpiderValue **Arguments ); +/** + * \brief Convert a script to bytecode and save to a file + */ +extern int SpiderScript_SaveBytecode(tSpiderScript *Script, const char *DestFile); +/** + * \brief Save the AST of a script to a file + */ +extern int SpiderScript_SaveAST(tSpiderScript *Script, const char *Filename); + /** * \brief Free a script * \param Script Script structure to free */ extern void SpiderScript_Free(tSpiderScript *Script); +extern tSpiderObject *SpiderScript_AllocateObject(tSpiderObjectDef *Class, int ExtraBytes); + /** * \name tSpiderValue Manipulation functions * \{ */ +extern void SpiderScript_DereferenceValue(tSpiderValue *Object); +extern void SpiderScript_ReferenceValue(tSpiderValue *Object); extern tSpiderValue *SpiderScript_CreateInteger(uint64_t Value); extern tSpiderValue *SpiderScript_CreateReal(double Value); extern tSpiderValue *SpiderScript_CreateString(int Length, const char *Data); +extern tSpiderValue *SpiderScript_StringConcat(const tSpiderValue *Str1, const tSpiderValue *Str2); extern tSpiderValue *SpiderScript_CastValueTo(int Type, tSpiderValue *Source); extern int SpiderScript_IsValueTrue(tSpiderValue *Value); +extern void SpiderScript_FreeValue(tSpiderValue *Value); extern char *SpiderScript_DumpValue(tSpiderValue *Value); + +extern tSpiderValue *SpiderScript_DoOp(tSpiderValue *Left, enum eSpiderValueOps Op, int bCanCast, tSpiderValue *Right); /** * \} */