00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef __ASEBA_VM_H
00025 #define __ASEBA_VM_H
00026
00027 #ifdef __cplusplus
00028 extern "C" {
00029 #endif
00030
00031 #include "../common/types.h"
00032
00056
00057 enum
00058 {
00059 ASEBA_MAX_BREAKPOINTS = 16
00060 };
00061
00072 typedef struct
00073 {
00074
00075 uint16 nodeId;
00076
00077
00078 uint16 bytecodeSize;
00079 uint16 * bytecode;
00081
00082 uint16 variablesSize;
00083 sint16 * variables;
00085
00086 uint16 stackSize;
00087 sint16 * stack;
00089
00090 uint16 flags;
00091 uint16 pc;
00092 sint16 sp;
00093
00094
00095 uint16 breakpoints[ASEBA_MAX_BREAKPOINTS];
00096 uint16 breakpointsCount;
00097 } AsebaVMState;
00098
00099
00100
00102 #define AsebaMaskSet(v, m) ((v) |= (m))
00103
00104 #define AsebaMaskClear(v, m) ((v) &= (~(m)))
00105
00106 #define AsebaMaskIsSet(v, m) (((v) & (m)) != 0)
00107
00108 #define AsebaMaskIsClear(v, m) (((v) & (m)) == 0)
00109
00110
00111
00112
00113
00119 void AsebaVMInit(AsebaVMState *vm);
00120
00122 uint16 AsebaVMGetEventAddress(AsebaVMState *vm, uint16 event);
00123
00127 uint16 AsebaVMSetupEvent(AsebaVMState *vm, uint16 event);
00128
00133 uint16 AsebaVMRun(AsebaVMState *vm, uint16 stepsLimit);
00134
00137 void AsebaVMDebugMessage(AsebaVMState *vm, uint16 id, uint16 *data, uint16 dataLength);
00138
00140 void AsebaVMEmitNodeSpecificError(AsebaVMState *vm, const char* message);
00141
00143 uint16 AsebaVMShouldDropPacket(AsebaVMState *vm, uint16 source, const uint8* data);
00144
00145
00146
00149 void AsebaSendMessage(AsebaVMState *vm, uint16 id, void *data, uint16 size);
00150
00152 void AsebaSendVariables(AsebaVMState *vm, uint16 start, uint16 length);
00153
00155 void AsebaSendDescription(AsebaVMState *vm);
00156
00158 void AsebaNativeFunction(AsebaVMState *vm, uint16 id);
00159
00161 void AsebaWriteBytecode(AsebaVMState *vm);
00162
00164 void AsebaResetIntoBootloader(AsebaVMState *vm);
00165
00167 void AsebaPutVmToSleep(AsebaVMState *vm);
00168
00169
00170
00171 #ifdef ASEBA_ASSERT
00172
00174 typedef enum
00175 {
00176 ASEBA_ASSERT_UNKNOWN = 0,
00177 ASEBA_ASSERT_UNKNOWN_UNARY_OPERATOR,
00178 ASEBA_ASSERT_UNKNOWN_BINARY_OPERATOR,
00179 ASEBA_ASSERT_UNKNOWN_BYTECODE,
00180 ASEBA_ASSERT_STACK_OVERFLOW,
00181 ASEBA_ASSERT_STACK_UNDERFLOW,
00182 ASEBA_ASSERT_OUT_OF_VARIABLES_BOUNDS,
00183 ASEBA_ASSERT_OUT_OF_BYTECODE_BOUNDS,
00184 ASEBA_ASSERT_STEP_OUT_OF_RUN,
00185 ASEBA_ASSERT_BREAKPOINT_OUT_OF_BYTECODE_BOUNDS,
00186 ASEBA_ASSERT_EMIT_BUFFER_TOO_LONG,
00187 } AsebaAssertReason;
00188
00190 void AsebaAssert(AsebaVMState *vm, AsebaAssertReason reason);
00191
00192 #endif
00193
00196 #ifdef __cplusplus
00197 }
00198 #endif
00199
00200 #endif