00001 /* 00002 Aseba - an event-based framework for distributed robot control 00003 Copyright (C) 2007--2009: 00004 Stephane Magnenat <stephane at magnenat dot net> 00005 (http://stephane.magnenat.net) 00006 and other contributors, see authors.txt for details 00007 Mobots group, Laboratory of Robotics Systems, EPFL, Lausanne 00008 00009 This program is free software: you can redistribute it and/or modify 00010 it under the terms of the GNU General Public License as published by 00011 the Free Software Foundation, either version 3 of the License, or 00012 any other version as decided by the two original authors 00013 Stephane Magnenat and Valentin Longchamp. 00014 00015 This program is distributed in the hope that it will be useful, 00016 but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 GNU General Public License for more details. 00019 00020 You should have received a copy of the GNU General Public License 00021 along with this program. If not, see <http://www.gnu.org/licenses/>. 00022 */ 00023 00024 #ifndef VIRTUALMACHINE_H 00025 #define VIRTUALMACHINE_H 00026 00027 #include "Target.h" 00028 #include "../compiler/compiler.h" 00029 #include "../vm/vm.h" 00030 00031 namespace Aseba 00032 { 00034 class LocalVirtualMachine : public Target 00035 { 00036 public: 00038 LocalVirtualMachine(); 00039 00040 virtual bool connect() { return true; } 00041 00042 virtual const TargetDescription * const getConstDescription() { return &description; } 00043 virtual TargetDescription * getDescription() { return &description; } 00044 virtual void uploadBytecode(const BytecodeVector &bytecode); 00045 00046 virtual void sizesChanged(); 00047 00048 virtual void setupEvent(unsigned id); 00049 00050 virtual void next(); 00051 virtual void runStepSwitch(); 00052 virtual void runBackground(); 00053 virtual void stop(); 00054 00055 virtual bool setBreakpoint(unsigned line); 00056 virtual bool clearBreakpoint(unsigned line); 00057 virtual void clearBreakpoints(); 00058 00059 public: 00060 // The following functions should only be called by the VM C bindings. They call the corresponding Qt signals or popup a message box 00061 void emitEvent(unsigned short id, unsigned short start, unsigned short length); 00062 void emitArrayAccessOutOfBounds(unsigned short pc, unsigned short sp, unsigned short index); 00063 void emitDivisionByZero(unsigned short pc, unsigned short sp); 00064 00065 protected: 00066 void timerEvent(QTimerEvent *event); 00067 00068 protected: 00069 TargetDescription description; 00070 bool runEvent; 00071 AsebaVMState vmState; 00072 std::valarray<uint16> vmBytecode; 00073 std::valarray<sint16> vmVariables; 00074 std::valarray<sint16> vmStack; 00075 BytecodeVector debugBytecode; 00076 }; 00077 }; // Aseba 00078 00079 #endif