~ubuntu-branches/ubuntu/trusty/rlvm/trusty

« back to all changes in this revision

Viewing changes to src/libReallive/expression.cpp

  • Committer: Package Import Robot
  • Author(s): Ying-Chun Liu (PaulLiu)
  • Date: 2013-11-02 02:57:13 UTC
  • mfrom: (10.1.3 sid)
  • Revision ID: package-import@ubuntu.com-20131102025713-yzg31grxr8i7xerh
Tags: 0.13-1
* New upstream release
  - rlvm will now warn on startup when it detects Japanese save data, but
    English patched game files, and offer to reset the save data.
  - Much better support for Little Busters. Most graphical glitches during
    the Little Busters Refrain have been fixed.
  - TCC tone curve effects have been reverse-engineered and implemented
    (thanks to lurkmoar)
  - Sepia scenes (and other graphical filters) should look much better.
  - Simple shake commands implemented (fancy per-layer shaking still
    unimplemented).
  - Make animations smooth: data should be uploaded to the graphics card
    before an animation loop starts, not while the animation loop is
    running.
  - Fixes finding system fonts on Linux
  - Thanks to Elliot Glaysher <glaysher@umich.edu>
* Remove upstreamed patches:
  - debian/patches/002_675426ad62bccf1de10b0ae31dd46331ec47aacb.patch
  - debian/patches/003_5dafabf5448635c4d4526d6e35ea7ec664a27261.patch
  - debian/patches/004_boost-drop-mt.patch
  - debian/patches/005_missing-include.patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
42
42
#include <sstream>
43
43
 
44
44
#include <boost/algorithm/string/predicate.hpp>
 
45
#include <boost/lexical_cast.hpp>
45
46
#include <boost/tokenizer.hpp>
46
47
#include "defs.h"
47
48
 
104
105
size_t next_string(const char* src) {
105
106
  bool quoted = false;
106
107
  const char* end = src;
 
108
 
107
109
  while (true) {
108
110
    if (quoted) {
109
111
      quoted = *end != '"';
 
112
      if (!quoted && *(end - 1) != '\\') {
 
113
        end++;  // consume the final quote
 
114
        break;
 
115
      }
110
116
    } else {
111
117
      quoted = *end == '"';
112
118
      if (strncmp(end, "###PRINT(", 9) == 0) {
123
129
    else
124
130
      ++end;
125
131
  }
 
132
 
126
133
  return end - src;
127
134
}
128
135
 
140
147
    const char* end = src;
141
148
    if (*end++ == 'a') {
142
149
      ++end;
 
150
 
 
151
      // Some special cases have multiple tags.
 
152
      if (*end == 'a')
 
153
        end += 2;
 
154
 
143
155
      if (*end != '(') {
144
156
        end += next_data(end);
145
157
        return end - src;
146
158
      } else end++;
147
159
    }
 
160
 
148
161
    while (*end != ')') end += next_data(end);
149
162
    end++;
150
163
    if (*end == '\\')
373
386
 
374
387
    if (*end++ == 'a') {
375
388
      int tag = *end++;
 
389
 
 
390
      // Some special cases have multiple tags.
 
391
      if (*end == 'a') {
 
392
        end++;
 
393
        int second = *end++;
 
394
        tag = (second << 16) | tag;
 
395
      }
 
396
 
376
397
      cep.reset(new SpecialExpressionPiece(tag));
377
398
 
378
399
      if (*end != '(') {
405
426
    }
406
427
 
407
428
    return cep.release();
408
 
  } else
 
429
  } else {
409
430
    return get_expression(src);
 
431
  }
410
432
}
411
433
 
412
434
std::string evaluatePRINT(RLMachine& machine, const std::string& in) {
487
509
ExpressionPiece::~ExpressionPiece()              {}
488
510
bool ExpressionPiece::isMemoryReference() const  { return false; }
489
511
bool ExpressionPiece::isOperator() const         { return false; }
 
512
bool ExpressionPiece::isAssignment() const       { return false; }
490
513
bool ExpressionPiece::isComplexParameter() const { return false; }
491
514
bool ExpressionPiece::isSpecialParamater() const { return false; }
492
515
 
542
565
  return IntToBytecode(machine.getStoreRegisterValue());
543
566
}
544
567
 
 
568
std::string StoreRegisterExpressionPiece::getDebugValue(RLMachine& machine) const {
 
569
  return boost::lexical_cast<std::string>(machine.getStoreRegisterValue());
 
570
}
 
571
 
 
572
std::string StoreRegisterExpressionPiece::getDebugString() const {
 
573
  return "<store>";
 
574
}
 
575
 
545
576
IntReferenceIterator StoreRegisterExpressionPiece::getIntegerReferenceIterator(
546
577
    RLMachine& machine) const {
547
578
  return IntReferenceIterator(machine.storeRegisterAddress());
568
599
  return IntToBytecode(constant);
569
600
}
570
601
 
 
602
std::string IntegerConstant::getDebugValue(RLMachine& machine) const {
 
603
  return boost::lexical_cast<std::string>(constant);
 
604
}
 
605
 
 
606
std::string IntegerConstant::getDebugString() const {
 
607
  return boost::lexical_cast<std::string>(constant);
 
608
}
 
609
 
571
610
ExpressionPiece* IntegerConstant::clone() const {
572
611
  return new IntegerConstant(constant);
573
612
}
590
629
  return string("\"") + constant + string("\"");
591
630
}
592
631
 
 
632
std::string StringConstant::getDebugValue(RLMachine& machine) const {
 
633
  return serializedValue(machine);
 
634
}
 
635
 
 
636
std::string StringConstant::getDebugString() const {
 
637
  return string("\"") + constant + string("\"");
 
638
}
 
639
 
593
640
ExpressionPiece* StringConstant::clone() const {
594
641
  return new StringConstant(constant);
595
642
}
642
689
  }
643
690
}
644
691
 
 
692
std::string MemoryReference::getDebugValue(RLMachine& machine) const {
 
693
  if (isStringLocation(type)) {
 
694
    return string("\"") + getStringValue(machine) + string("\"");
 
695
  } else {
 
696
    return boost::lexical_cast<std::string>(integerValue(machine));
 
697
  }
 
698
}
 
699
 
 
700
std::string MemoryReference::getDebugString() const {
 
701
  ostringstream ret;
 
702
 
 
703
  if (type == STRS_LOCATION)
 
704
    ret << "strS[";
 
705
  else if (type == STRK_LOCATION)
 
706
    ret << "strK[";
 
707
  else if (type == STRM_LOCATION)
 
708
    ret << "strM[";
 
709
  else if (type == INTZ_LOCATION_IN_BYTECODE)
 
710
    ret << "intZ[";
 
711
  else if (type == INTL_LOCATION_IN_BYTECODE)
 
712
    ret << "intL[";
 
713
  else {
 
714
    char bank = 'A' + (type % 26);
 
715
    ret << "int" << bank << "[";
 
716
  }
 
717
 
 
718
  ret << location->getDebugString();
 
719
 
 
720
  ret << "]";
 
721
  return ret.str();
 
722
}
 
723
 
645
724
IntReferenceIterator MemoryReference::getIntegerReferenceIterator(
646
725
    RLMachine& machine) const {
647
726
  // Make sure that we are actually referencing an integer
702
781
  return IntToBytecode(integerValue(machine));
703
782
}
704
783
 
 
784
std::string UniaryExpressionOperator::getDebugValue(RLMachine& machine) const {
 
785
  return boost::lexical_cast<std::string>(integerValue(machine));
 
786
}
 
787
 
 
788
std::string UniaryExpressionOperator::getDebugString() const {
 
789
  ostringstream str;
 
790
  if (operation == 0x01) {
 
791
    str << "-";
 
792
  }
 
793
  str << operand->getDebugString();
 
794
 
 
795
  return str.str();
 
796
}
 
797
 
705
798
ExpressionPiece* UniaryExpressionOperator::clone() const {
706
799
  return new UniaryExpressionOperator(operation, operand->clone());
707
800
}
776
869
  return IntToBytecode(integerValue(machine));
777
870
}
778
871
 
 
872
std::string BinaryExpressionOperator::getDebugValue(RLMachine& machine) const {
 
873
  return boost::lexical_cast<std::string>(integerValue(machine));
 
874
}
 
875
 
 
876
std::string BinaryExpressionOperator::getDebugString() const {
 
877
  ostringstream str;
 
878
  str << leftOperand->getDebugString();
 
879
  str << " ";
 
880
 
 
881
  switch (operation) {
 
882
  case 0:
 
883
  case 20:
 
884
    str << "+";
 
885
    break;
 
886
  case 1:
 
887
  case 21:
 
888
    str << "-";
 
889
    break;
 
890
  case 2:
 
891
  case 22:
 
892
    str << "*";
 
893
    break;
 
894
  case 3:
 
895
  case 23:
 
896
    str << "/";
 
897
    break;
 
898
  case 4:
 
899
  case 24:
 
900
    str << "%";
 
901
    break;
 
902
  case 5:
 
903
  case 25:
 
904
    str << "&";
 
905
    break;
 
906
  case 6:
 
907
  case 26:
 
908
    str << "|";
 
909
    break;
 
910
  case 7:
 
911
  case 27:
 
912
    str << "^";
 
913
    break;
 
914
  case 8:
 
915
  case 28:
 
916
    str << "<<";
 
917
    break;
 
918
  case 9:
 
919
  case 29:
 
920
    str << ">>";
 
921
    break;
 
922
  case 30:
 
923
    str << "=";
 
924
    break;
 
925
  case 40:
 
926
    str << "==";
 
927
    break;
 
928
  case 41:
 
929
    str << "!=";
 
930
    break;
 
931
  case 42:
 
932
    str << "<=";
 
933
    break;
 
934
  case 43:
 
935
    str << "< ";
 
936
    break;
 
937
  case 44:
 
938
    str << ">=";
 
939
    break;
 
940
  case 45:
 
941
    str << "> ";
 
942
    break;
 
943
  case 60:
 
944
    str << "&&";
 
945
    break;
 
946
  case 61:
 
947
    str << "||";
 
948
    break;
 
949
  default: {
 
950
    ostringstream ss;
 
951
    ss << "Invalid operator " << (int)operation << " in expression!";
 
952
    throw Error(ss.str());
 
953
  }
 
954
  }
 
955
 
 
956
  if (isAssignment() && operation != 30) {
 
957
    str << "=";
 
958
  }
 
959
 
 
960
  str << " ";
 
961
  str << rightOperand->getDebugString();
 
962
 
 
963
  return str.str();
 
964
}
 
965
 
779
966
ExpressionPiece* BinaryExpressionOperator::clone() const {
780
967
  return new BinaryExpressionOperator(operation, leftOperand->clone(),
781
968
                                      rightOperand->clone());
792
979
AssignmentExpressionOperator::~AssignmentExpressionOperator() {
793
980
}
794
981
 
 
982
bool AssignmentExpressionOperator::isAssignment() const {
 
983
  return true;
 
984
}
 
985
 
795
986
int AssignmentExpressionOperator::integerValue(RLMachine& machine) const {
796
987
  if (operation == 30) {
797
988
    int value = rightOperand->integerValue(machine);
805
996
  }
806
997
}
807
998
 
 
999
std::string AssignmentExpressionOperator::getDebugValue(
 
1000
    RLMachine& machine) const {
 
1001
  return "<assignment>";
 
1002
}
 
1003
 
808
1004
ExpressionPiece* AssignmentExpressionOperator::clone() const {
809
1005
  return new AssignmentExpressionOperator(operation, leftOperand->clone(),
810
1006
                                          rightOperand->clone());
833
1029
  return s;
834
1030
}
835
1031
 
 
1032
std::string ComplexExpressionPiece::getDebugValue(RLMachine& machine) const {
 
1033
  return "<complex value>";
 
1034
}
 
1035
 
 
1036
std::string ComplexExpressionPiece::getDebugString() const {
 
1037
  string s("(");
 
1038
  for (boost::ptr_vector<ExpressionPiece>::const_iterator it =
 
1039
           containedPieces.begin(); it != containedPieces.end(); ++it) {
 
1040
    s += "(";
 
1041
    s += it->getDebugString();
 
1042
    s += ")";
 
1043
  }
 
1044
  s += ")";
 
1045
  return s;
 
1046
}
 
1047
 
836
1048
ExpressionPiece* ComplexExpressionPiece::clone() const {
837
1049
  ComplexExpressionPiece* cep = new ComplexExpressionPiece;
838
1050
  cep->containedPieces = containedPieces.clone();
865
1077
  return s;
866
1078
}
867
1079
 
 
1080
std::string SpecialExpressionPiece::getDebugValue(RLMachine& machine) const {
 
1081
  ostringstream oss;
 
1082
 
 
1083
  oss << int(overloadTag) << ":{";
 
1084
 
 
1085
  bool first = true;
 
1086
 
 
1087
  for (boost::ptr_vector<ExpressionPiece>::const_iterator it =
 
1088
           containedPieces.begin(); it != containedPieces.end(); ++it) {
 
1089
    if (!first) {
 
1090
      oss << ", ";
 
1091
    } else {
 
1092
      first = false;
 
1093
    }
 
1094
 
 
1095
    oss << it->getDebugValue(machine);
 
1096
  }
 
1097
  oss << "}";
 
1098
 
 
1099
  return oss.str();
 
1100
}
 
1101
 
 
1102
std::string SpecialExpressionPiece::getDebugString() const {
 
1103
  ostringstream oss;
 
1104
 
 
1105
  oss << int(overloadTag) << ":{";
 
1106
 
 
1107
  bool first = true;
 
1108
  for (boost::ptr_vector<ExpressionPiece>::const_iterator it =
 
1109
           containedPieces.begin(); it != containedPieces.end(); ++it) {
 
1110
    if (!first) {
 
1111
      oss << ", ";
 
1112
    } else {
 
1113
      first = false;
 
1114
    }
 
1115
 
 
1116
    oss << it->getDebugString();
 
1117
  }
 
1118
  oss << "}";
 
1119
 
 
1120
  return oss.str();
 
1121
}
 
1122
 
868
1123
ExpressionPiece* SpecialExpressionPiece::clone() const {
869
1124
  SpecialExpressionPiece* cep = new SpecialExpressionPiece(overloadTag);
870
1125
  cep->containedPieces = containedPieces.clone();