diff options
| author | manuel <manuel@clan-server.at> | 2009-05-13 15:29:51 +0200 |
|---|---|---|
| committer | manuel <manuel@clan-server.at> | 2009-05-13 15:29:51 +0200 |
| commit | 431bbac5a99abbccf33500e22aa353ec792eff94 (patch) | |
| tree | 0649a2833c7ee5f6cbce145b719c104c7efe19df /ue3/mycpu/cprogram.cpp | |
| parent | 89e202f49b9857dcd3627fbc4e0262125d729bbc (diff) | |
| download | ooprog-431bbac5a99abbccf33500e22aa353ec792eff94.tar.gz ooprog-431bbac5a99abbccf33500e22aa353ec792eff94.tar.bz2 ooprog-431bbac5a99abbccf33500e22aa353ec792eff94.zip | |
* adding -Wno-long-long to all Makefiles
* adding execute operator to cinstruction
* added labels map for better performance
Diffstat (limited to 'ue3/mycpu/cprogram.cpp')
| -rw-r--r-- | ue3/mycpu/cprogram.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/ue3/mycpu/cprogram.cpp b/ue3/mycpu/cprogram.cpp index f6fc3cb..f904bce 100644 --- a/ue3/mycpu/cprogram.cpp +++ b/ue3/mycpu/cprogram.cpp | |||
| @@ -107,6 +107,16 @@ void CProgram::compile(std::istream& in) | |||
| 107 | /* let instruction parse the parameters. catch+throw exception */ | 107 | /* let instruction parse the parameters. catch+throw exception */ |
| 108 | try | 108 | try |
| 109 | { | 109 | { |
| 110 | /* handle label instruction ourself, but still add a dummy instruction */ | ||
| 111 | if (instrname == "label") | ||
| 112 | { | ||
| 113 | if (instrparams.size() != 1) | ||
| 114 | throw runtime_error("Invalid paramater count - must be 1"); | ||
| 115 | string label = instrparams.front(); | ||
| 116 | if (label.length() < 2 || label[ label.length() - 1] != ':') | ||
| 117 | throw runtime_error("Label has invalid syntax"); | ||
| 118 | m_labels[ label.substr(0, label.length() - 1) ] = size(); | ||
| 119 | } | ||
| 110 | instr->compile(instrparams); | 120 | instr->compile(instrparams); |
| 111 | } | 121 | } |
| 112 | catch(runtime_error& ex) | 122 | catch(runtime_error& ex) |
| @@ -123,6 +133,17 @@ void CProgram::compile(std::istream& in) | |||
| 123 | 133 | ||
| 124 | /*----------------------------------------------------------------------------*/ | 134 | /*----------------------------------------------------------------------------*/ |
| 125 | 135 | ||
| 136 | unsigned CProgram::findLabel(const std::string& label) const | ||
| 137 | { | ||
| 138 | map<string, unsigned>::const_iterator it; | ||
| 139 | it = m_labels.find(label); | ||
| 140 | if (it == m_labels.end()) | ||
| 141 | throw runtime_error("Unknown label '" + label + "'"); | ||
| 142 | return it->second; | ||
| 143 | } | ||
| 144 | |||
| 145 | /*----------------------------------------------------------------------------*/ | ||
| 146 | |||
| 126 | #if DEBUG | 147 | #if DEBUG |
| 127 | void CProgram::dump(std::ostream& out) | 148 | void CProgram::dump(std::ostream& out) |
| 128 | { | 149 | { |
