Canola  0.8.D001
lib/interpose/stateful.cc
Go to the documentation of this file.
00001 //
00002 // canola - canon canola 1614p emulator
00003 // Copyright (C) 2011 Peter Miller
00004 //
00005 // This program is free software; you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License, version 3, as
00007 // published by the Free Software Foundation.
00008 //
00009 // This program is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012 // General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License along
00015 // with this program. If not, see <http://www.gnu.org/licenses/>.
00016 //
00017 
00018 #include <lib/interpose/goto.h>
00019 #include <lib/interpose/memory/cm.h>
00020 #include <lib/interpose/memory/m.h>
00021 #include <lib/interpose/memory/rm.h>
00022 #include <lib/interpose/memory/sm.h>
00023 #include <lib/interpose/stateful.h>
00024 
00025 
00026 interpose_stateful::~interpose_stateful()
00027 {
00028 }
00029 
00030 
00031 interpose_stateful::interpose_stateful(const pointer &a_deeper, bool a_jumper) :
00032     deeper(a_deeper),
00033     jumper(a_jumper),
00034     diversion()
00035 {
00036 }
00037 
00038 
00039 interpose::pointer
00040 interpose_stateful::create(const pointer &a_deeper, bool a_jumper)
00041 {
00042     return pointer(new interpose_stateful(a_deeper, a_jumper));
00043 }
00044 
00045 
00046 void
00047 interpose_stateful::on_opcode(opcode_t op, const location::pointer &where)
00048 {
00049     if (diversion)
00050     {
00051         diversion->on_opcode(op, where);
00052         diversion.reset();
00053         return;
00054     }
00055     switch (op)
00056     {
00057     case opcode_zero:
00058         assert(!"this isn't supposed to be possible");
00059         break;
00060 
00061     case opcode_plus_equals:
00062     case opcode_minus_equals:
00063     case opcode_mul:
00064     case opcode_div:
00065     case opcode_sqrt:
00066     case opcode_ent:
00067     case opcode_sj:
00068     case opcode_ej:
00069     case opcode_mj:
00070         goto boring;
00071 
00072     case opcode_uj:
00073         if (!jumper)
00074             goto boring;
00075         diversion = interpose_goto::create(deeper);
00076         break;
00077 
00078     case opcode_fj:
00079     case opcode_suj:
00080     case opcode_sfj:
00081     case opcode_srj:
00082     case opcode_m1:
00083     case opcode_m2:
00084     case opcode_m3:
00085     case opcode_m4:
00086     case opcode_m5:
00087     case opcode_m6:
00088     case opcode_m7:
00089     case opcode_m8:
00090     case opcode_m9:
00091     case opcode_m10:
00092     case opcode_m11:
00093     case opcode_m12:
00094     case opcode_m13:
00095     case opcode_m14:
00096     case opcode_mm1:
00097     case opcode_mm2:
00098     case opcode_sm3:
00099     case opcode_sm4:
00100     case opcode_sm5:
00101     case opcode_sm6:
00102     case opcode_sm7:
00103     case opcode_sm8:
00104     case opcode_sm9:
00105     case opcode_sm10:
00106     case opcode_sm11:
00107     case opcode_sm12:
00108     case opcode_sm13:
00109     case opcode_sm14:
00110     case opcode_rm1:
00111     case opcode_rm2:
00112     case opcode_rm3:
00113     case opcode_rm4:
00114     case opcode_rm5:
00115     case opcode_rm6:
00116     case opcode_rm7:
00117     case opcode_rm8:
00118     case opcode_rm9:
00119     case opcode_rm10:
00120     case opcode_rm11:
00121     case opcode_rm12:
00122     case opcode_rm13:
00123     case opcode_rm14:
00124     case opcode_clear_indicator:
00125     case opcode_cm1:
00126     case opcode_cm2:
00127     case opcode_cm3:
00128     case opcode_cm4:
00129     case opcode_cm5:
00130     case opcode_cm6:
00131     case opcode_cm7:
00132     case opcode_cm8:
00133     case opcode_cm9:
00134     case opcode_cm10:
00135     case opcode_cm11:
00136     case opcode_cm12:
00137     case opcode_cm13:
00138     case opcode_cm14:
00139     case opcode_dot:
00140     case opcode_rv:
00141     case opcode_right:
00142     case opcode_chg_sign:
00143     case opcode_round_down:
00144     case opcode_round_off:
00145     case opcode_round_up:
00146     case opcode_print:
00147     case opcode_fd:
00148     case opcode_n0:
00149     case opcode_n1:
00150     case opcode_n2:
00151     case opcode_n3:
00152     case opcode_n4:
00153     case opcode_n5:
00154     case opcode_n6:
00155     case opcode_n7:
00156     case opcode_n8:
00157     case opcode_n9:
00158     case opcode_n10:
00159     case opcode_n11:
00160     case opcode_n12:
00161     case opcode_n13:
00162     case opcode_n14:
00163     case opcode_extended_c:
00164     case opcode_extended_start:
00165         boring:
00166         deeper->on_opcode(op, where);
00167         break;
00168 
00169     case opcode_extended_m3_tilde:
00170         diversion = interpose_memory_m::create(deeper, where);
00171         break;
00172 
00173     case opcode_extended_sm3_tilde:
00174         diversion = interpose_memory_sm::create(deeper, where);
00175         break;
00176 
00177     case opcode_extended_rm3_tilde:
00178         diversion = interpose_memory_rm::create(deeper, where);
00179         break;
00180 
00181     case opcode_extended_cm3_tilde:
00182         diversion = interpose_memory_cm::create(deeper, where);
00183         break;
00184 
00185     case opcode_extended_off:
00186     case opcode_extended_program_print:
00187     case opcode_extended_display_print:
00188     case opcode_extended_paper_feed:
00189     case opcode_extended_rounding_switch_up:
00190     case opcode_extended_rounding_switch_off:
00191     case opcode_extended_rounding_switch_down:
00192     case opcode_extended_decimal_point_selector_0:
00193     case opcode_extended_decimal_point_selector_1:
00194     case opcode_extended_decimal_point_selector_2:
00195     case opcode_extended_decimal_point_selector_3:
00196     case opcode_extended_decimal_point_selector_4:
00197     case opcode_extended_decimal_point_selector_5:
00198     case opcode_extended_decimal_point_selector_6:
00199     case opcode_extended_decimal_point_selector_7:
00200     case opcode_extended_decimal_point_selector_8:
00201     case opcode_extended_decimal_point_selector_9:
00202     case opcode_extended_decimal_point_selector_10:
00203     case opcode_extended_decimal_point_selector_11:
00204     case opcode_extended_decimal_point_selector_12:
00205     case opcode_extended_decimal_point_selector_float:
00206     case opcode_extended_goto_000:
00207     case opcode_extended_goto_001:
00208     case opcode_extended_goto_002:
00209     case opcode_extended_goto_003:
00210     case opcode_extended_goto_004:
00211     case opcode_extended_goto_005:
00212     case opcode_extended_goto_006:
00213     case opcode_extended_goto_007:
00214     case opcode_extended_goto_008:
00215     case opcode_extended_goto_009:
00216     case opcode_extended_goto_010:
00217     case opcode_extended_goto_011:
00218     case opcode_extended_goto_012:
00219     case opcode_extended_goto_013:
00220     case opcode_extended_goto_014:
00221     case opcode_extended_goto_015:
00222     case opcode_extended_goto_100:
00223     case opcode_extended_goto_101:
00224     case opcode_extended_goto_102:
00225     case opcode_extended_goto_103:
00226     case opcode_extended_goto_104:
00227     case opcode_extended_goto_105:
00228     case opcode_extended_goto_106:
00229     case opcode_extended_goto_107:
00230     case opcode_extended_goto_108:
00231     case opcode_extended_goto_109:
00232     case opcode_extended_goto_110:
00233     case opcode_extended_goto_111:
00234     case opcode_extended_goto_112:
00235     case opcode_extended_goto_113:
00236     case opcode_extended_goto_114:
00237     case opcode_extended_goto_115:
00238     case opcode_extended_goto_200:
00239     case opcode_extended_goto_201:
00240     case opcode_extended_goto_202:
00241     case opcode_extended_goto_203:
00242     case opcode_extended_goto_204:
00243     case opcode_extended_goto_205:
00244     case opcode_extended_goto_206:
00245     case opcode_extended_goto_207:
00246     case opcode_extended_goto_208:
00247     case opcode_extended_goto_209:
00248     case opcode_extended_goto_210:
00249     case opcode_extended_goto_211:
00250     case opcode_extended_goto_212:
00251     case opcode_extended_goto_213:
00252     case opcode_extended_goto_214:
00253     case opcode_extended_goto_215:
00254     case opcode_extended_goto_300:
00255     case opcode_extended_goto_301:
00256     case opcode_extended_goto_302:
00257     case opcode_extended_goto_303:
00258     case opcode_extended_goto_304:
00259     case opcode_extended_goto_305:
00260     case opcode_extended_goto_306:
00261     case opcode_extended_goto_307:
00262     case opcode_extended_goto_308:
00263     case opcode_extended_goto_309:
00264     case opcode_extended_goto_310:
00265     case opcode_extended_goto_311:
00266     case opcode_extended_goto_312:
00267     case opcode_extended_goto_313:
00268     case opcode_extended_goto_314:
00269     case opcode_extended_goto_315:
00270     case opcode_extended_goto_400:
00271     case opcode_extended_goto_401:
00272     case opcode_extended_goto_402:
00273     case opcode_extended_goto_403:
00274     case opcode_extended_goto_404:
00275     case opcode_extended_goto_405:
00276     case opcode_extended_goto_406:
00277     case opcode_extended_goto_407:
00278     case opcode_extended_goto_408:
00279     case opcode_extended_goto_409:
00280     case opcode_extended_goto_410:
00281     case opcode_extended_goto_411:
00282     case opcode_extended_goto_412:
00283     case opcode_extended_goto_413:
00284     case opcode_extended_goto_414:
00285     case opcode_extended_goto_415:
00286     case opcode_extended_goto_500:
00287     case opcode_extended_goto_501:
00288     case opcode_extended_goto_502:
00289     case opcode_extended_goto_503:
00290     case opcode_extended_goto_504:
00291     case opcode_extended_goto_505:
00292     case opcode_extended_goto_506:
00293     case opcode_extended_goto_507:
00294     case opcode_extended_goto_508:
00295     case opcode_extended_goto_509:
00296     case opcode_extended_goto_510:
00297     case opcode_extended_goto_511:
00298     case opcode_extended_goto_512:
00299     case opcode_extended_goto_513:
00300     case opcode_extended_goto_514:
00301     case opcode_extended_goto_515:
00302     case opcode_extended_goto_600:
00303     case opcode_extended_goto_601:
00304     case opcode_extended_goto_602:
00305     case opcode_extended_goto_603:
00306     case opcode_extended_goto_604:
00307     case opcode_extended_goto_605:
00308     case opcode_extended_goto_606:
00309     case opcode_extended_goto_607:
00310     case opcode_extended_goto_608:
00311     case opcode_extended_goto_609:
00312     case opcode_extended_goto_610:
00313     case opcode_extended_goto_611:
00314     case opcode_extended_goto_612:
00315     case opcode_extended_goto_613:
00316     case opcode_extended_goto_614:
00317     case opcode_extended_goto_615:
00318     case opcode_extended_goto_700:
00319     case opcode_extended_goto_701:
00320     case opcode_extended_goto_702:
00321     case opcode_extended_goto_703:
00322     case opcode_extended_goto_704:
00323     case opcode_extended_goto_705:
00324     case opcode_extended_goto_706:
00325     case opcode_extended_goto_707:
00326     case opcode_extended_goto_708:
00327     case opcode_extended_goto_709:
00328     case opcode_extended_goto_710:
00329     case opcode_extended_goto_711:
00330     case opcode_extended_goto_712:
00331     case opcode_extended_goto_713:
00332     case opcode_extended_goto_714:
00333     case opcode_extended_goto_715:
00334     default:
00335         goto boring;
00336     }
00337 }
00338 
00339 
00340 void
00341 interpose_stateful::on_error_v(const char *fmt, va_list ap)
00342 {
00343     deeper->on_error_v(fmt, ap);
00344 }
00345 
00346 
00347 bool
00348 interpose_stateful::strict_memory_number_checking_required(void)
00349     const
00350 {
00351     return deeper->strict_memory_number_checking_required();
00352 }