00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #include <stdlib.h>
00039 #include <assert.h>
00040
00041
00042 #include "Options.hxx"
00043 #include "Type.hxx"
00044 #include "Trail.hxx"
00045
00046 using namespace boost;
00047 using namespace sherpa;
00048
00061 void
00062 Trail::link(shared_ptr<Type> from, shared_ptr<Type> to)
00063 {
00064 from = from->getType();
00065 to = to->getType();
00066
00067 if (to->boundInType(from)) {
00068 std::cerr << "CYCLIC SUBSTITUTION "
00069 << from->asString(Options::debugTvP)
00070 << " |-> "
00071 << to->asString(Options::debugTvP)
00072 << std::endl;
00073 assert(false);
00074 }
00075
00076 DEBUG(TRAIL)
00077 std::cerr << "LINKING: "
00078 << from->asString(Options::debugTvP)
00079 << " |-> "
00080 << to->asString(Options::debugTvP)
00081 << std::endl;
00082
00083 vec.push_back(from);
00084 from->link = to;
00085 }
00086
00087 void
00088 Trail::subst(shared_ptr<Type> from, shared_ptr<Type> to)
00089 {
00090 from = from->getType();
00091 to = to->getType();
00092
00093 assert(from->typeTag == ty_tvar || from->typeTag == ty_kvar);
00094
00095 if (to->boundInType(from)) {
00096 std::cerr << "CYCLIC SUBSTITUTION "
00097 << from->asString(Options::debugTvP)
00098 << " |-> "
00099 << to->asString(Options::debugTvP)
00100 << std::endl;
00101 assert(false);
00102 }
00103
00104 DEBUG(TRAIL)
00105 std::cerr << "SUBSTITUTING: "
00106 << from->asString(Options::debugTvP)
00107 << " |-> "
00108 << to->asString(Options::debugTvP)
00109 << std::endl;
00110
00111
00112 vec.push_back(from);
00113 from->link = to;
00114 }
00115
00116 void
00117 Trail::rollBack(size_t upto)
00118 {
00119 assert(upto <= vec.size());
00120
00121 for (size_t i = upto; i < vec.size(); i++) {
00122 vec[i]->link = GC_NULL;
00123 DEBUG(TRAIL)
00124 std::cerr << "[RB] Releasing: "
00125 << vec[i]->asString(Options::debugTvP)
00126 << std::endl;
00127 }
00128
00129 vec.erase(vec.begin() + upto, vec.end());
00130 }
00131
00132 void
00133 Trail::release(const size_t n, shared_ptr<Type> rel)
00134 {
00135 assert(vec[n] == rel);
00136
00137 rel->link = GC_NULL;
00138
00139 DEBUG(TRAIL)
00140 std::cerr << "[RB] Releasing: "
00141 << rel->asString(Options::debugTvP)
00142 << std::endl;
00143
00144 vec.erase(vec.begin() + n);
00145 }