2 #ifndef HOBBES_LANG_TYPELIFT_HPP_INCLUDED 3 #define HOBBES_LANG_TYPELIFT_HPP_INCLUDED 25 virtual bool isTypeName(
const std::string&)
const = 0;
62 template <const
char* TN,
typename T>
107 bool empty()
const {
return get<unit>(this->data) != 0; }
108 const pair_t*
head()
const {
return get<pair_t>(this->data); }
114 template <
typename T,
bool InStruct = false,
typename P =
void>
128 template <
typename T,
bool InStruct>
134 template <
typename T,
bool InStruct,
typename P>
144 template <
bool InStruct>
148 template <
typename T>
156 template <
typename T,
bool InStruct>
160 template <
typename T>
167 template <
typename T,
bool InStruct>
170 template <
bool InStruct>
178 template <
typename F,
typename S>
181 typedef std::pair<F,S> FS;
189 template <
typename F,
typename S>
191 template <
typename F,
typename S>
196 template <
typename T>
203 template <
typename T,
bool InStruct>
207 #define HOBBES_LIFT_PRIMITIVE(T, n) \ 208 template <bool InStruct> \ 209 struct lift<T, InStruct> { \ 210 static MonoTypePtr type(typedb&) { \ 211 return Prim::make(#n); \ 231 template <
typename T>
235 template <const
char* TN,
typename T,
bool InStruct>
242 template <const
char* TN,
typename T,
bool InStruct>
251 template <
typename T,
size_t N>
258 template <
typename T,
size_t N,
bool InStruct>
260 template <
typename T,
size_t N,
bool InStruct>
262 template <
typename T,
size_t N,
bool InStruct>
264 template <
typename T,
size_t N,
bool InStruct>
266 template <
typename T,
size_t N,
bool InStruct>
268 template <
typename T,
size_t N,
bool InStruct>
272 template <
typename ... Ts>
277 template <
typename T,
typename ... Ts>
286 template <
typename F>
289 template <
typename R,
typename ...
Args>
296 template <
typename R,
typename ...
Args>
298 template <
typename R,
typename ...
Args>
300 template <
typename R,
typename ...
Args>
302 template <
typename R,
typename ...
Args>
309 template <const
char* TN,
typename T>
314 static std::string
name() {
return TN; }
316 template <
typename T,
typename P =
void>
321 template <const
char* TN,
typename T>
326 template <
typename ... CTys>
330 template <
typename CTy,
typename ... CTys>
338 template <
typename T>
340 template <
typename ... CTys>
347 size_t vsz = vty->
size();
348 size_t csz =
sizeof(
variant<CTys...>);
352 throw std::runtime_error(
353 "Internal error, computed size for variant '" +
show(result) +
"' (" +
355 ")) inconsistent with C++ memory layout (size=" +
str::from(csz) +
")" 362 template <
typename ... CTys>
364 template <
typename ... CTys>
368 #define HOBBES_ENUM_CTOR(n, v) n = v, 369 #define HOBBES_ENUM_METAENT(n, v) r.push_back(MetaEnt(#n, v)); 371 #define DEFINE_ENUM(T, CTORS...) \ 373 enum Enum : unsigned int { \ 374 _HOBPP_MAP(HOBBES_ENUM_CTOR, CTORS) \ 376 explicit operator bool() const = delete; \ 378 typedef void is_hobbes_enum; \ 379 typedef std::pair<std::string, unsigned int> MetaEnt; \ 380 typedef std::vector<MetaEnt> MetaSeq; \ 382 static MetaSeq meta() { \ 384 _HOBPP_MAP(HOBBES_ENUM_METAENT, CTORS) \ 389 operator Enum() const { \ 390 return this->value; \ 392 T& operator=(Enum x) { \ 396 T() : value(Enum()) { } \ 397 T(const T& x) : value(x.value) { } \ 398 T(Enum x) : value(x) { } \ 401 template <
typename T>
406 typedef typename T::MetaSeq MS;
408 for (
typename MS::const_iterator
m = ms.begin();
m != ms.end(); ++
m) {
416 template <
typename T>
417 struct lift<T, true, typename T::is_hobbes_enum> :
public liftEnum<T> { };
418 template <
typename T>
422 #define HOBBES_STRUCT_FIELD(t, n) t n; 423 #define HOBBES_META_FIELD(t, n) r.push_back(::hobbes::Record::Member(#n, ::hobbes::lift<t, true>::type(tenv), offsetof(SelfT, n))); 425 #define DEFINE_STRUCT(T, FIELDS...) \ 427 _HOBPP_MAP(HOBBES_STRUCT_FIELD, FIELDS) \ 429 typedef void is_hobbes_struct; \ 431 static ::hobbes::MonoTypePtr meta(::hobbes::typedb& tenv) { \ 432 ::hobbes::Record::Members r; \ 433 _HOBPP_MAP(HOBBES_META_FIELD, FIELDS) \ 434 return ::hobbes::Record::make(r); \ 438 template <
typename T>
441 return T::meta(tenv);
445 template <
typename T>
447 template <
typename T>
451 template <
typename T>
std::shared_ptr< PolyType > PolyTypePtr
Definition: type.H:23
T type
Definition: tylift.H:318
seq(const T &x, seq< T > *xs)
Definition: tylift.H:105
nulltypedb nulltdb
Definition: type.C:2239
variant< unit, pair_t > rep_t
Definition: tylift.H:101
static MonoTypePtr make(const std::string &, const MonoTypePtr &t=MonoTypePtr())
Definition: type.C:613
const bool unit
Definition: data.C:8
bool empty() const
Definition: tylift.H:107
static void accum(MonoTypes *, typedb &)
Definition: tylift.H:274
std::vector< Member > Members
Definition: type.H:385
virtual bool isTypeName(const std::string &) const =0
MonoTypePtr arrayty(const MonoTypePtr &ty, size_t n)
Definition: type.H:1155
static MonoTypePtr make(const MonoTypePtr &)
Definition: type.C:747
static void constructors(typedb &tenv, Variant::Members *ms)
Definition: tylift.H:332
unsigned int payloadSize() const
Definition: type.C:993
typeAlias()
Definition: tylift.H:65
MonoTypePtr prim()
Definition: tylift.H:232
static MonoTypePtr type(typedb &tenv)
Definition: tylift.H:150
virtual PolyTypePtr generalize(const MonoTypePtr &mt) const =0
virtual PolyTypePtr opaquePtrPolyType(const std::type_info &, unsigned int sz, bool inStruct)=0
static MonoTypePtr type()
Definition: tylift.H:119
MonoTypePtr primty(const char *x)
Definition: type.H:1008
virtual MonoTypePtr defineNamedType(const std::string &name, const str::seq &argNames, const MonoTypePtr &ty)=0
static MonoTypePtr type(typedb &)
Definition: tylift.H:143
std::vector< R > second(const std::vector< std::pair< L, R > > &xs)
Definition: array.H:228
Definition: pattern.H:281
std::pair< std::string, std::string > pair
Definition: str.H:220
T value
Definition: tylift.H:72
void * value
Definition: tylift.H:75
static MonoTypePtr type(typedb &)
Definition: tylift.H:403
static MonoTypePtr type(typedb &tenv)
Definition: tylift.H:440
static MonoTypePtr type(typedb &tenv)
Definition: tylift.H:162
std::string from(const T &x)
Definition: str.H:101
unsigned int size() const
Definition: type.C:1003
static std::string name()
Definition: tylift.H:314
long size
Definition: tylift.H:84
llvm::Value * offset(llvm::IRBuilder<> *b, llvm::Value *p, llvm::Value *o0)
Definition: llvm.H:419
static MonoTypePtr type(typedb &tenv)
Definition: tylift.H:130
static void constructors(typedb &, Variant::Members *)
Definition: tylift.H:328
static MonoTypePtr make(const std::string &, const MonoTypePtr &)
Definition: type.C:1431
static std::string labelText(int idx)
Definition: tylift.H:324
MonoType::ptr MonoTypePtr
Definition: type.H:71
static MonoTypePtr make(const std::string &nm, unsigned int sz, bool scontig=false)
Definition: type.C:628
std::pair< T, seq< T > * > pair_t
Definition: tylift.H:100
static MonoTypePtr type(typedb &tenv, T)
Definition: tylift.H:453
virtual MonoTypePtr namedTypeRepresentation(const std::string &) const =0
const pair_t * head() const
Definition: tylift.H:108
static MonoTypePtr type(typedb &)
Definition: tylift.H:172
seq()
Definition: tylift.H:104
unsigned int payloadOffset() const
Definition: type.C:985
MonoTypePtr functy(const MonoTypePtr &aty, const MonoTypePtr &rty)
Definition: type.H:1109
static MonoTypePtr type(typedb &)
Definition: tylift.H:123
HOBBES_LIFT_PRIMITIVE(void, unit)
static MonoTypePtr type(typedb &tenv)
Definition: tylift.H:342
std::string show(const Expr &e)
Definition: expr.C:19
array< T > * ptr
Definition: tylift.H:82
const T * end(const array< T > *d)
Definition: tylift.H:88
static MonoTypePtr type(typedb &tenv)
Definition: tylift.H:253
static MonoTypes liftSeq(typedb &tenv)
Definition: tylift.H:283
virtual MonoTypePtr replaceTypeAliases(const MonoTypePtr &ty) const =0
std::vector< T > list()
Definition: array.H:25
const T * begin(const array< T > *d)
Definition: tylift.H:87
MonoTypePtr tvar(const std::string &vn)
Definition: type.H:1060
size_t r(const reader::MetaData &md, size_t o, T *t)
Definition: storage.H:1730
static MonoTypePtr type(typedb &tenv)
Definition: tylift.H:198
Definition: variant.H:165
std::vector< std::string > seq
Definition: str.H:19
rep_t data
Definition: tylift.H:102
static MonoTypePtr type(typedb &tenv)
Definition: tylift.H:244
static std::string labelText(int idx)
Definition: tylift.H:319
static MonoTypePtr make(const Members &ms)
Definition: type.C:1037
static MonoTypePtr type(typedb &tenv)
Definition: tylift.H:180
static MonoTypePtr type(typedb &)
Definition: tylift.H:145
static MonoTypePtr make(const Members &)
Definition: type.C:760
recursion(void *x)
Definition: tylift.H:76
uint32_t result
Definition: regex.C:376
T type
Definition: tylift.H:311
typeAlias(const T &v)
Definition: tylift.H:64
T data[1]
Definition: tylift.H:85
std::vector< Member > Members
Definition: type.H:435
static void accum(MonoTypes *r, typedb &tenv)
Definition: tylift.H:279
virtual MonoTypePtr opaquePtrMonoType(const std::type_info &, unsigned int sz, bool inStruct)=0
label< TN, T >::type type
Definition: tylift.H:323
virtual void defineTypeAlias(const std::string &name, const str::seq &argNames, const MonoTypePtr &ty)=0
static MonoTypePtr type(typedb &tenv)
Definition: tylift.H:136
virtual bool isTypeAliasName(const std::string &name) const =0
std::map< std::string, llvm::Value * > Args
Definition: dfa.C:1276
std::vector< MonoTypePtr > MonoTypes
Definition: type.H:72
static MonoTypePtr type(typedb &tenv)
Definition: tylift.H:237
std::vector< L > first(const std::vector< std::pair< L, R > > &xs)
Definition: array.H:208
MonoTypePtr tuple(const MonoTypes &mtys=MonoTypes())
Definition: type.H:1068
static MonoTypePtr type()
Definition: tylift.H:120
LexicalAnnotation m(const YYLTYPE &p)
Definition: hexpr.parse.C:127
T value
Definition: tylift.H:66
static MonoTypePtr type(typedb &tenv)
Definition: tylift.H:291
static MonoTypes liftSeq(typedb &)
Definition: tylift.H:275
T value
Definition: tylift.H:312
label(const T &x)
Definition: tylift.H:313