1
0

vcpu.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. #ifndef __VCPU_H
  2. #define __VCPU_H
  3. #include "script.h"
  4. #include "opcodes.h"
  5. #include <bfc/tlist.h>
  6. #include <bfc/ptrlist.h>
  7. #include <bfc/stack.h>
  8. #include <bfc/critsec.h>
  9. #include <api/script/script.h>
  10. #include <api/script/scriptmgr.h>
  11. #include <api/script/objects/systemobj.h>
  12. class ConsoleEnum;
  13. #include <api/script/vcputypes.h>
  14. class OrphanEntry {
  15. public:
  16. OrphanEntry(int _id, int type);
  17. virtual ~OrphanEntry() {}
  18. int id;
  19. VCPUscriptVar v;
  20. };
  21. class OrphanQuickSort {
  22. public:
  23. static int compareItem(void *p1, void* p2);
  24. static int compareAttrib(const wchar_t *attrib, void *item);
  25. };
  26. class ScriptAtom {
  27. public:
  28. ScriptAtom(const wchar_t *atomname, ScriptObject *object) : name(atomname), obj(object) {}
  29. ~ScriptAtom() {}
  30. const wchar_t *getAtomName() { return name; }
  31. ScriptObject *getAtomObject() { return obj; }
  32. private:
  33. StringW name;
  34. ScriptObject *obj;
  35. };
  36. class ScriptAtomSort {
  37. public:
  38. static int compareItem(ScriptAtom *p1, ScriptAtom*p2) {
  39. return WCSICMP(p1->getAtomName(), p2->getAtomName());
  40. }
  41. static int compareAttrib(const wchar_t *attrib, ScriptAtom *item) {
  42. return WCSICMP(attrib, item->getAtomName());
  43. }
  44. };
  45. class VCPU {
  46. public:
  47. static void shutdown();
  48. static int assignNewScriptId();
  49. static int addScript(void *mem, int memsize, int cpuid);
  50. static void removeScript(int id);
  51. static void push(VCPUscriptVar v);
  52. static void push(scriptVar v);
  53. static VCPUscriptVar pop();
  54. static VCPUscriptVar peekAt(int n);
  55. static scriptVar executeEvent(scriptVar v, int functionId, int np, int vcpuid=-1);
  56. static int runEvent(VCPUeventEntry *e, int np, int pbase);
  57. static void runCode(int scriptId, int pointer, int np);
  58. static scriptVar callDLF(VCPUdlfEntry *e, int np);
  59. static scriptVar VCPUassign(int id, scriptVar sv, int scriptId);
  60. static int findObject(ScriptObject *o, int start, int dlfid, int vcpuid=-1);
  61. static int numScripts;
  62. static void setupDLF(VCPUdlfEntry *e, int base);
  63. static void delrefDLF(VCPUdlfEntry *e);
  64. static void setupDLFFunction(void *ptr, int nargs, int DLFid, VCPUdlfEntry *e);
  65. static int getDlfGlobalIndex(int dlfid, int scriptid);
  66. static scriptVar safeDiv(VCPUscriptVar*, VCPUscriptVar*);
  67. static void setComplete() { complete=1; }
  68. static void resetComplete() { complete=0; }
  69. static int getComplete();
  70. static int newDlf();
  71. static void resetDlf();
  72. static PtrList<VCPUscriptVar> variablesTable;
  73. static PtrList<VCPUeventEntry> eventsTable;
  74. static PtrList<VCPUdlfEntry> DLFentryTable;
  75. static PtrList<VCPUcodeBlock> codeTable;
  76. static int highestDLFId;
  77. static Stack<VCPUscriptVar> CpuStack;
  78. static Stack<char *> CallStack;
  79. static int varBase(int scriptId);
  80. static int dlfBase(int scriptId);
  81. static int nVars(int scriptId);
  82. static char *getCodeBlock(int scriptId, int *size=NULL);
  83. static VCPUcodeBlock *getCodeBlockEntry(int vcpuid);
  84. static void addStatementString(wchar_t *s);
  85. static int getCacheCount();
  86. static int getUserAncestor(int varid, int scriptid);
  87. static int isValidScriptId(int id);
  88. static int oldClassToClassId(int id);
  89. static const wchar_t *getClassName(int vcpuid, int localclassid);
  90. static int VIP;
  91. static int VSP;
  92. static int VSD;
  93. static int VCC;
  94. static int complete;
  95. static int cacheCount;
  96. static Stack<int> VIPstack;
  97. static Stack<int> VSPstack;
  98. static Stack<int> VSDstack;
  99. static Stack<int> VCCstack;
  100. static void RemoveOldScripts();
  101. static TList<int> scriptsToRemove;
  102. static scriptVar paramList[SCRIPT_MAXARGS];
  103. static TList<VCPUscriptVar> plist;
  104. static PtrList<wchar_t> statementStringList;
  105. static int isInstantiable(int id);
  106. static void pushObject(void *o);
  107. static void pushInt(int i);
  108. static void pushBoolean(int b);
  109. static void pushFloat(float f);
  110. static void pushDouble(double d);
  111. static void pushString(const wchar_t *s);
  112. static void pushVoid();
  113. static void *popObject();
  114. static int popInt();
  115. static bool popBoolean();
  116. static float popFloat();
  117. static double popDouble();
  118. static const wchar_t *popString();
  119. static void popDiscard();
  120. static void callDlfCommand(void *ptr, int nargs, maki_cmd *cmd);
  121. static int getDLFFromPointer(void *ptr, int nargs);
  122. static void DLF_addref(void *ptr, int nargs);
  123. static void DLF_reset(void *ptr, int nargs);
  124. static void DLF_remref(void *ptr, int nargs);
  125. static VCPUdlfEntry *getGlobalDlfEntry(int dlfid);
  126. static void registerGlobalDlf(VCPUdlfEntry *e, int dlf);
  127. static void traceState(VCPUscriptVar object, VCPUdlfEntry *e);
  128. static PtrList<VCPUdlfEntry> globalDlfList;
  129. static PtrListInsertSorted< OrphanEntry, OrphanQuickSort >orphans;
  130. static int orphanid;
  131. static VCPUscriptVar *getOrphan(int id);
  132. static int createOrphan(int type);
  133. static void killOrphan(int id);
  134. static void setAtom(const wchar_t *atomname, ScriptObject *o);
  135. static ScriptObject *getAtom(const wchar_t *atomname);
  136. static PtrListQuickSorted<ScriptAtom, ScriptAtomSort> atoms;
  137. static ScriptObjectManager *scriptManager;
  138. };
  139. #endif