Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef __ASEBA_VM_H
00022 #define __ASEBA_VM_H
00023
00024 #ifdef __cplusplus
00025 extern "C" {
00026 #endif
00027
00028 #include "../common/types.h"
00029
00053
00054 enum
00055 {
00056 ASEBA_MAX_BREAKPOINTS = 16
00057 };
00058
00069 typedef struct
00070 {
00071
00072 uint16 nodeId;
00073
00074
00075 uint16 bytecodeSize;
00076 uint16 * bytecode;
00078
00079 uint16 variablesSize;
00080 sint16 * variables;
00082
00083 uint16 stackSize;
00084 sint16 * stack;
00086
00087 uint16 flags;
00088 uint16 pc;
00089 sint16 sp;
00090
00091
00092 uint16 breakpoints[ASEBA_MAX_BREAKPOINTS];
00093 uint16 breakpointsCount;
00094 } AsebaVMState;
00095
00096
00097
00099 #define AsebaMaskSet(v, m) ((v) |= (m))
00100
00101 #define AsebaMaskClear(v, m) ((v) &= (~(m)))
00102
00103 #define AsebaMaskIsSet(v, m) (((v) & (m)) != 0)
00104
00105 #define AsebaMaskIsClear(v, m) (((v) & (m)) == 0)
00106
00107
00108
00109
00110
00116 void AsebaVMInit(AsebaVMState *vm);
00117
00119 uint16 AsebaVMGetEventAddress(AsebaVMState *vm, uint16 event);
00120
00124 uint16 AsebaVMSetupEvent(AsebaVMState *vm, uint16 event);
00125
00130 uint16 AsebaVMRun(AsebaVMState *vm, uint16 stepsLimit);
00131
00134 void AsebaVMDebugMessage(AsebaVMState *vm, uint16 id, uint16 *data, uint16 dataLength);
00135
00137 void AsebaVMEmitNodeSpecificError(AsebaVMState *vm, const char* message);
00138
00140 uint16 AsebaVMShouldDropPacket(AsebaVMState *vm, uint16 source, const uint8* data);
00141
00142
00143
00146 void AsebaSendMessage(AsebaVMState *vm, uint16 id, const void *data, uint16 size);
00147
00148 #ifdef __BIG_ENDIAN__
00149
00151 void AsebaSendMessageWords(AsebaVMState *vm, uint16 type, const uint16* data, uint16 count);
00152 #else
00153 #define AsebaSendMessageWords(vm,type,data,size) AsebaSendMessage(vm,type,data,(size)*2)
00154 #endif
00155
00157 void AsebaSendVariables(AsebaVMState *vm, uint16 start, uint16 length);
00158
00160 void AsebaSendDescription(AsebaVMState *vm);
00161
00163 void AsebaNativeFunction(AsebaVMState *vm, uint16 id);
00164
00166 void AsebaWriteBytecode(AsebaVMState *vm);
00167
00169 void AsebaResetIntoBootloader(AsebaVMState *vm);
00170
00172 void AsebaPutVmToSleep(AsebaVMState *vm);
00173
00175 void __attribute__((weak)) AsebaVMRunCB(AsebaVMState *vm);
00176
00179 void __attribute__((weak)) AsebaVMErrorCB(AsebaVMState *vm, const char* message);
00180
00181
00182
00183 #ifdef ASEBA_ASSERT
00184
00186 typedef enum
00187 {
00188 ASEBA_ASSERT_UNKNOWN = 0,
00189 ASEBA_ASSERT_UNKNOWN_UNARY_OPERATOR,
00190 ASEBA_ASSERT_UNKNOWN_BINARY_OPERATOR,
00191 ASEBA_ASSERT_UNKNOWN_BYTECODE,
00192 ASEBA_ASSERT_STACK_OVERFLOW,
00193 ASEBA_ASSERT_STACK_UNDERFLOW,
00194 ASEBA_ASSERT_OUT_OF_VARIABLES_BOUNDS,
00195 ASEBA_ASSERT_OUT_OF_BYTECODE_BOUNDS,
00196 ASEBA_ASSERT_STEP_OUT_OF_RUN,
00197 ASEBA_ASSERT_BREAKPOINT_OUT_OF_BYTECODE_BOUNDS,
00198 ASEBA_ASSERT_EMIT_BUFFER_TOO_LONG,
00199 } AsebaAssertReason;
00200
00202 void AsebaAssert(AsebaVMState *vm, AsebaAssertReason reason);
00203
00204 #endif
00205
00208 #ifdef __cplusplus
00209 }
00210 #endif
00211
00212 #endif