C:/Projets/hexamonkey/core/interpreter/blockexecution.h
Go to the documentation of this file.
00001 #ifndef BLOCKEXECUTION_H
00002 #define BLOCKEXECUTION_H
00003 
00004 class Module;
00005 class ContainerParser;
00006 class Scope;
00007 class Evaluator;
00008 
00009 #include <memory>
00010 
00011 #include "core/interpreter/program.h"
00012 #include "core/interpreter/scope/scopeptr.h"
00013 
00020 class BlockExecution
00021 {
00022 public:
00030     BlockExecution(Program block,
00031                    const Evaluator& evaluator,
00032                    Scope& scope,
00033                    ContainerParser* parser = nullptr);
00034 
00038     enum class ExitCode
00039     {
00041         NoExit,
00043         EndReached,
00045         BreakPointReached,
00048         QuotaExhausted,
00050         Broken,
00052         Continued,
00054         Returned
00055     };
00056 
00060     ExitCode execute();
00061 
00065     ExitCode execute(Program::const_iterator breakpoint);
00066 
00071     ExitCode execute(size_t& parseQuota);
00072 
00077     ExitCode execute(Program::const_iterator breakpoint, size_t& parseQuota);
00078 
00082     bool done();
00083 
00088     Variable returnValue();
00089 
00090 private:
00091     bool hasParser();
00092     ContainerParser& parser();
00093 
00094     void setSubBlock(Program program, bool loop);
00095     void resetSubBlock();
00096 
00097     void handleDeclaration(const Program& declaration, size_t& parseQuota);
00098     void handleLocalDeclarations(const Program& declarations);
00099     void handleSubscopeAssign(const Program& assign);
00100     void handleRemove(const Program& remove);
00101     void handleRightValue(const Program& rightValue);
00102     void handleCondition(const Program& condition);
00103     void handleLoop(const Program& loop);
00104     void handleDoLoop(const Program& loop);
00105     bool handleBreak();
00106     bool handleContinue();
00107     void handleReturn(const Program& line);
00108 
00109     bool loopCondition(const Program& loop);
00110     static bool hasDeclaration(const Program& instructions);
00111 
00112     ScopePtr handleScope(const Program& scope);
00113 
00114     Program program;
00115     const Program::const_iterator begin;
00116     const Program::const_iterator end;
00117     Program::const_iterator current;
00118     Program::const_iterator last;
00119     unsigned int lineRepeatCount;
00120 
00121     const Evaluator& eval;
00122     Scope& scope;
00123     ContainerParser* _parser;
00124 
00125     Variable _returnValue;
00126 
00127     bool _inLoop;
00128 
00129     std::unique_ptr<BlockExecution> subBlock;
00130     ExitCode _subBlockExitCode;
00131 };
00132 
00133 #endif // BLOCKEXECUTION_H